home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Multimedia / Movie3.0 / Source / xanim / xanim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-03  |  98.8 KB  |  3,450 lines

  1.  
  2. /*
  3.  * xanim.c
  4.  *
  5.  * Copyright (C) 1990,1991,1992,1993,1994 by Mark Podlipec. 
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  * 
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18. /****************
  19.  * Rev History
  20.  *
  21.  * 12Aug94 - Setup X11 error handler to detec XShmAttach failures when Disp
  22.  *           is remote so I can backoff Shm support and continue on.
  23.  *
  24.  *******************************/
  25.  
  26.  
  27. #define DA_REV 2.68
  28. #define DA_MINOR_REV 5
  29.  
  30. /*
  31.  * Any problems, suggestions, solutions, anims to show off, etc contact:
  32.  *
  33.  * podlipec@wellfleet.com
  34.  *
  35.  */
  36.  
  37. #include "xanim.h"
  38.  
  39. #if XWIN
  40. #include <Intrinsic.h>
  41. #include <StringDefs.h>
  42. #include <Shell.h>
  43. #endif
  44.  
  45. #include <sys/signal.h>
  46. #ifdef MSDOS
  47. #include <sys/resource.h>
  48. #else /* not MSDOS */
  49. #ifndef VMS   /* NOT MSDOS and NOT VMS ie Unix */
  50. #include <sys/time.h>
  51. #else   /* VMS systems */
  52. #include <lib$routines.h>
  53. #include <starlet.h>
  54. #ifdef R3_INTRINSICS
  55. typedef void *XtPointer;
  56. #endif
  57. #endif
  58. #endif
  59. #include <ctype.h>
  60.  
  61. #ifdef XSHM
  62. #include <sys/ipc.h>
  63. #include <sys/shm.h>
  64. #include <X11/extensions/XShm.h>
  65. extern Visual        *theVisual;
  66. #endif /*XSHM*/
  67.  
  68. #if XWIN
  69. #include "xanim_x11.h"
  70. #endif
  71.  
  72.  
  73. /* POD TESTING */
  74. ULONG fli_pad_kludge;
  75.  
  76. void TheEnd();
  77. void TheEnd1();
  78. void Hard_Death();
  79. void Usage();
  80. void Usage_Quick();
  81. void ShowAnimation();
  82. void ShowAction();
  83. LONG Determine_Anim_Type();
  84. void XA_Cycle_Wait();
  85. void XA_Cycle_It();
  86. void Step_File_Next();
  87. void Step_File_Prev();
  88. void Step_Frame_Next();
  89. void Step_Frame_Prev();
  90. void Step_Action_Next();
  91. void Free_Actions();
  92. void ACT_Free_Act();
  93. XA_ANIM_HDR *Get_Anim_Hdr();
  94. XA_ANIM_HDR *Return_Anim_Hdr();
  95. void Step_Action_Prev();
  96. LONG XA_Time_Read();
  97. void XA_Time_Init();
  98. void XA_Time_Check();
  99. ULONG XA_Image_To_Pixmap();
  100. void XA_Install_CMAP();
  101. ULONG XA_Mapped_To_Display();
  102. ULONG XA_Read_Int();
  103. float XA_Read_Float();
  104. LONG XA_Get_Class();
  105. void XA_Read_Delta();
  106. void XA_Add_Pause();
  107.  
  108. void X11_Setup_Window();
  109. void X11_Map_Window();
  110. void X11_Init_Image_Struct();
  111. void X11_Pre_Setup();
  112. void ACT_Make_Images();
  113. void UTIL_Mapped_To_Mapped();
  114. void UTIL_Mapped_To_Bitmap();
  115. void UTIL_Mapped_To_Floyd();
  116. UBYTE *UTIL_Scale_Mapped();
  117. UBYTE *UTIL_Scale_Bitmap();
  118. void UTIL_Pack_Image();
  119.  
  120. void CMAP_Manipulate_CHDRS();
  121. void CMAP_Expand_Maps();
  122. ULONG CMAP_Gamma_Adjust();
  123.  
  124. ULONG IFF_Read_File();
  125. void IFF_Buffer_Action();
  126. void IFF_Init_DLTA_HDR();
  127. void IFF_Update_DLTA_HDR();
  128. void IFF_Buffer_HAM6();
  129. void IFF_Buffer_HAM8();
  130. ULONG GIF_Read_Anim();
  131. ULONG TXT_Read_File();
  132. ULONG Fli_Read_File();
  133. ULONG DL_Read_File();
  134. ULONG PFX_Read_File();
  135. ULONG RLE_Read_File();
  136. ULONG AVI_Read_File();
  137. ULONG QT_Read_File();
  138.  
  139. LONG Is_IFF_File();
  140. LONG Is_GIF_File();
  141. LONG Is_TXT_File();
  142. LONG Is_FLI_File();
  143. LONG Is_DL_File();
  144. LONG Is_PFX_File();
  145. LONG Is_RLE_File();
  146. LONG Is_AVI_File();
  147. LONG Is_QT_File();
  148.  
  149. #if SETFILE
  150. ULONG SET_Read_File();
  151. LONG Is_SET_File();
  152. #endif
  153.  
  154. ULONG shm = 0;
  155. #ifdef XSHM
  156. XShmSegmentInfo im0_shminfo;
  157. XShmSegmentInfo im1_shminfo;
  158. XShmSegmentInfo im2_shminfo;
  159. XImage *im0_Image = 0;
  160. XImage *im1_Image = 0;
  161. XImage *im2_Image = 0;
  162. XImage *sh_Image = 0;
  163. #endif
  164.  
  165. #ifdef VMS
  166. /*      
  167.  *      Provide the UNIX gettimeofday() function for VMS C.
  168.  *      The timezone is currently unsupported.
  169.  */
  170.  
  171. struct timeval {
  172.     long tv_sec;
  173.     long tv_usec;
  174. };
  175.  
  176. struct timezone {
  177.     int tz_minuteswest;
  178.     int tz_dsttime;
  179. };
  180.  
  181. int gettimeofday( tp, tzp)
  182. struct timeval *tp;
  183. struct timezone *tzp;
  184. {
  185.    long curr_time[2];   /* Eight byte VAX time variable */
  186.    long jan_01_1970[2] = { 0x4BEB4000,0x7C9567} ;
  187.    long diff[2];
  188.    long result;
  189.    long vax_sec_conv = 10000000;
  190.  
  191.    result = sys$gettim( &curr_time );
  192.  
  193.    result = lib$subx( &curr_time, &jan_01_1970, &diff);
  194.  
  195.    if ( tp != 0) {
  196.        result = lib$ediv( &vax_sec_conv, &diff,
  197.                           &(tp->tv_sec), &(tp->tv_usec) );
  198.        tp->tv_usec = tp->tv_usec / 10;  /* convert 1.e-7 to 1.e-6 */
  199.    }
  200.    if ( tzp !=0) { tzp->tz_minuteswest = 0; tzp->tz_dsttime=0;}
  201.  
  202.    return ( 0);
  203. }
  204. #endif
  205.  
  206.  
  207. /*
  208.  * Global X11 display configuation variables
  209.  *
  210.  * These are set by X11_Pre_Setup();
  211.  *
  212.  */
  213.  
  214. LONG x11_error_possible = 0; /* -1 err occured. 0 no error. 1 err expected */
  215. LONG x11_depth;
  216. LONG x11_class;
  217. LONG x11_bytes_pixel;
  218. LONG x11_byte_order;
  219. LONG x11_bits_per_pixel;
  220. LONG x11_bitmap_pad;
  221. LONG x11_pack_flag;
  222. LONG x11_bitmap_unit;
  223. LONG x11_bit_order;
  224. LONG x11_cmap_flag;
  225. LONG x11_cmap_size;
  226. LONG x11_disp_bits;
  227. LONG x11_cmap_type;
  228. LONG x11_depth_mask;
  229. LONG x11_display_type;
  230. LONG x11_red_mask;
  231. LONG x11_green_mask;
  232. LONG x11_blue_mask;
  233. LONG x11_red_shift;
  234. LONG x11_green_shift;
  235. LONG x11_blue_shift;
  236. LONG x11_red_bits;
  237. LONG x11_green_bits;
  238. LONG x11_blue_bits;
  239. LONG x11_black;
  240. LONG x11_white;
  241. LONG x11_verbose_flag;
  242. LONG pod_max_colors;
  243. LONG xa_user_visual;
  244. LONG xa_user_class;
  245. ULONG x11_kludge_1;
  246.  
  247. /*
  248.  * Each animation is broken up into a series of individual actions.
  249.  * For example, a gif image would become two actions, 1 to setup the
  250.  * colormap and 1 to display the image.
  251.  *
  252.  * XA_ACTION is defined in xanim.h. 
  253.  *
  254.  * action_cnt is a global variable that points to the next unused action.
  255.  * Currently, individual routines access this. This will change.
  256.  *
  257.  * action_start is a variable passed to the Read_Animation routines, It
  258.  * keeps track of the 1st action available to routine.
  259.  *
  260.  */
  261.  
  262. /*
  263.  * anim_type is one of IFF_,FLI_,GIF_,TXT_,FADE_ANIM. 
  264.  *
  265.  * merged_anim_flags is the or of all anims read in. FLI's anims need
  266.  * only 1 buffer. IFF anims need two. This allows software to allocate
  267.  * for the worst case.
  268.  *
  269.  */
  270. ULONG xa_anim_type;
  271. ULONG xa_merged_anim_flags;
  272.  
  273.  
  274.  
  275. /*
  276.  * cmap keeps track of the current colors to the screen.
  277.  *
  278.  */
  279. LONG cmap_true_to_332;
  280. LONG cmap_true_to_gray;
  281. LONG cmap_true_to_1st;
  282. LONG cmap_true_to_all;
  283. LONG cmap_true_map_flag;
  284. LONG cmap_luma_sort;
  285. LONG cmap_map_to_1st_flag;
  286. LONG cmap_map_to_one_flag;
  287. LONG cmap_play_nice;
  288. LONG cmap_force_load;
  289. LONG xa_allow_nice;
  290. LONG cmap_hist_flag;
  291. LONG cmap_dither_type;
  292. LONG cmap_median_type;
  293. LONG cmap_median_bits;
  294. LONG cmap_use_combsort;
  295. double xa_disp_gamma;
  296. double xa_anim_gamma;
  297. ULONG xa_gamma_flag;
  298. USHORT xa_gamma_adj[256];
  299. XA_CHDR *xa_chdr_start;
  300. XA_CHDR *xa_chdr_cur;
  301. XA_CHDR *xa_chdr_now;
  302. XA_CHDR *xa_chdr_first;
  303. USHORT *cmap_cache;
  304. ULONG cmap_cache_size;
  305. ULONG cmap_cache_bits;
  306. ULONG cmap_cache_rmask;
  307. ULONG cmap_cache_gmask;
  308. ULONG cmap_cache_bmask;
  309. XA_CHDR *cmap_cache_chdr;
  310. SHORT cmap_floyd_error;
  311.  
  312. ULONG cmap_color_func;
  313. ULONG cmap_sample_cnt;   /* sample anim every X many frames for colors */
  314.  
  315. /*
  316.  * These are variables for HAM images
  317.  *
  318.  */
  319. ULONG xa_ham_map_size;
  320. ULONG *xa_ham_map;
  321. XA_CHDR *xa_ham_chdr;
  322. ULONG xa_ham_init;
  323. /*
  324.  * These are for converting TRUE images to PSEUDO
  325.  *
  326.  */
  327. ULONG xa_r_shift,xa_g_shift,xa_b_shift;
  328. ULONG xa_r_mask,xa_g_mask,xa_b_mask;
  329. ULONG xa_gray_bits,xa_gray_shift;
  330.  
  331. ColorReg *xa_cmap = 0;
  332. ULONG  xa_cmap_size,xa_cmap_off;
  333. ULONG  *xa_map;
  334. ULONG  xa_map_size,xa_map_off;
  335.  
  336. /*
  337.  * Global variable to keep track of Anim type
  338.  */
  339. LONG filetype;
  340. ULONG xa_title_flag;
  341. char xa_title[256];
  342.  
  343.  
  344. /*
  345.  * Global variables to keep track of current width, height, num of colors and
  346.  * number of bit planes respectively. 
  347.  *
  348.  * the max_ variable are used for worst case allocation. Are useful for Anims
  349.  * that have multiple image sizes.
  350.  *
  351.  * image_size and max_image_size are imagex * imagey, etc.
  352.  */
  353. ULONG xa_image_size;
  354. ULONG xa_max_image_size;
  355. ULONG xa_imagex,xa_max_imagex;
  356. ULONG xa_imagey,xa_max_imagey;
  357. ULONG xa_imaged;
  358.  
  359. /*
  360.  * Scaling Variable
  361.  *
  362.  */
  363.  
  364. ULONG xa_need_to_scale_b;
  365. ULONG xa_need_to_scale_u;
  366. float xa_scalex, xa_scaley;
  367. float xa_bscalex, xa_bscaley;
  368. ULONG xa_buff_x,xa_buff_y;        /* anim buffering size */
  369. ULONG xa_allow_lace;
  370. ULONG xa_allow_resizing;         /* allow window resizing */
  371. ULONG xa_disp_y, xa_max_disp_y;
  372. ULONG xa_disp_x, xa_max_disp_x;
  373. ULONG xa_disp_size;
  374. ULONG xa_max_disp_size;
  375. ULONG x11_display_x, x11_display_y;    /* max display size */
  376. ULONG x11_window_x, x11_window_y;    /* current window size */
  377. ULONG *xa_scale_row_buff;
  378. ULONG xa_scale_row_size;
  379. ULONG x11_expose_flag;
  380.  
  381. /* 
  382.  * These variable keep track of where we are in the animation.
  383.  * cur_file  ptr to the header of the current anim file. 
  384.  * cur_floop keeps track of how many times we've looped a file.
  385.  * cur_frame keeps track of which frame(action) we're on.
  386.  *
  387.  * xa_now_cycling and cycle_cnt are used for color cycling.
  388.  *
  389.  * file_is_started indicates whether this is the 1st time we've looped a file
  390.  * or not. Is used to initialize variables and resize window if necessary.
  391.  * 
  392.  */
  393. XA_ANIM_HDR *cur_file   = 0;
  394. XA_ANIM_HDR *first_file = 0;
  395. LONG xa_file_num;
  396. LONG cur_floop,cur_frame;
  397. LONG xa_cycle_cnt;      /* keeps track of number of cycling actions called */
  398. LONG xa_now_cycling;    /* indicates that cycling is now in progress */
  399. LONG xa_anim_cycling;   /* if set, allows cycling for animations */
  400. LONG file_is_started;
  401. int xa_fd;        /* Used if anim is being read from a file */
  402. char *xa_codec_buf;
  403. /*
  404.  * Image buffers.
  405.  * im_buff1 is used for double buffered anims(IFF).
  406.  * xa_disp_buff is needed when the display is of a different format than the
  407.  * double buffered images. (like HAM or TRUE_COLOR).
  408.  *
  409.  * xa_pic is a pointer to im_buff0 or im_buff1 during double buffering.
  410.  * im_buff2 is used for dithered or HAM images
  411.  */
  412. char *im_buff0,*im_buff1,*im_buff2,*im_buff3;
  413. char *xa_pic,*xa_disp_buff,*xa_scale_buff;
  414. ULONG xa_disp_buff_size,xa_scale_buff_size;
  415.  
  416. /*
  417.  * Variables for statistics
  418.  *
  419.  */
  420. LONG xa_time_start;
  421. LONG xa_time_end;
  422. LONG xa_time_off;
  423. LONG xa_no_disp;
  424. LONG xa_time_flag;
  425. LONG xa_time_av;
  426. LONG xa_time_num;
  427. struct timeval tv;
  428.  
  429.  
  430. /* 
  431.  * Global flags that are set on command line.
  432.  */
  433. LONG xa_buffer_flag;
  434. LONG x11_shared_flag;
  435. LONG xa_file_flag;
  436. LONG fade_flag,fade_time;
  437. LONG xa_noresize_flag;
  438. LONG xa_optimize_flag;
  439. LONG xa_pixmap_flag;
  440. LONG xa_dither_flag;
  441. LONG xa_pack_flag;
  442. LONG xa_debug;
  443. LONG xa_verbose;
  444.  
  445. LONG xa_loop_each_flag;
  446. LONG xa_pingpong_flag;
  447. LONG xa_jiffy_flag;
  448. ULONG xa_speed_scale;
  449.  
  450. LONG xa_anim_flags;
  451. LONG xa_anim_holdoff;
  452. LONG xa_anim_status;
  453. LONG xa_anim_ready = FALSE;
  454. LONG xa_use_depth_flag;
  455.  
  456. LONG xa_exit_flag;
  457.  
  458. XA_PAUSE *xa_pause_hdr=0;
  459.  
  460.  
  461. /*
  462.  * act is a global pointer to the current action.
  463.  *
  464.  */
  465. XA_ACTION *act;
  466.  
  467. void
  468. Usage_Quick()
  469. {
  470.   fprintf(stderr,"Usage:\n");
  471.   fprintf(stderr,"   XAnim [options] anim [ [options] anim ... ]\n");
  472.   fprintf(stderr,"   XAnim -h   for more detailed help.\n");
  473.   TheEnd();
  474. }
  475. void
  476. Usage_Default_TF(flag,justify)
  477. ULONG flag,justify;
  478. {
  479.   if (justify == 1) fprintf(stderr,"            ");
  480.   if (flag == TRUE) fprintf(stderr," default is on.\n");
  481.   else fprintf(stderr," default is off.\n");
  482. }
  483.  
  484. void
  485. Usage_Default_Num(num,justify)
  486. ULONG num,justify;
  487. {
  488.   if (justify == 1) fprintf(stderr,"            ");
  489.   fprintf(stderr," default is %ld.\n",num);
  490. }
  491.  
  492. /*
  493.  * This function attempts to expain XAnim's usage if the command line
  494.  * wasn't correct.
  495.  */
  496. void Usage()
  497. {
  498.  fprintf(stderr,"Usage:\n\n");
  499.  fprintf(stderr,"xanim [+V#] [ [+|-]opts ...] animfile [ [ [+|-opts] animfile] ... ]\n");
  500.  fprintf(stderr,"\n");
  501. #ifdef VMS
  502.  fprintf(stderr,"VMS users need to enclose opts in double qotes: \"+Cn\".\n");
  503.  fprintf(stderr,"\n");
  504. #endif
  505.  if (DEFAULT_PLUS_IS_ON == TRUE) 
  506.       fprintf(stderr,"A + turns an option on and a - turns it off.\n");
  507.  else fprintf(stderr,"A - turns an option on and a + turns it off.\n");
  508.  fprintf(stderr,"\n");
  509.  fprintf(stderr,"Options:\n");
  510.  fprintf(stderr,"\n  C[copts]  Color SubMenu\n");
  511.  fprintf(stderr,"       1    Create cmap from 1st TrueColor frame. Map\n");
  512.  fprintf(stderr,"            the rest to this first cmap.(Could be SLOW)\n");
  513.  fprintf(stderr,"       3    Convert TrueColor anims to 332(StaticColor).\n");
  514.  Usage_Default_TF(DEFAULT_TRUE_TO_332,1);
  515.  fprintf(stderr,"       a    Remap  all images to single new cmap.\n");
  516.  Usage_Default_TF(DEFAULT_CMAP_MAP_TO_ONE,1);
  517.  fprintf(stderr,"       d    Use floyd-steinberg dithering.\n");
  518.  Usage_Default_TF((DEFAULT_CMAP_DITHER_TYPE==CMAP_DITHER_FLOYD),1);
  519.  fprintf(stderr,"       f    Forcibly remap to 1st cmap\n");
  520.  Usage_Default_TF(DEFAULT_CMAP_MAP_TO_1ST,1);
  521.  fprintf(stderr,"       F4   Better(?) Color mapping for TrueColor anims.\n");
  522.  Usage_Default_TF(FALSE,1);
  523.  fprintf(stderr,"       g    Convert TrueColor anims to gray scale.\n");
  524.  Usage_Default_TF(DEFAULT_TRUE_TO_GRAY,1);
  525.  fprintf(stderr,"       h    Use histogram to aid in color reduction.\n");
  526.  Usage_Default_TF(DEFAULT_CMAP_HIST_FLAG,1);
  527.  fprintf(stderr,"       n    Be Nice: allocate colors from Default cmap.\n");
  528.  Usage_Default_TF(DEFAULT_CMAP_PLAY_NICE,1);
  529.  fprintf(stderr,"\n  G[gopts]  Gamma SubMenu\n");
  530.  fprintf(stderr,"       a#   Set gamma of animation. Default %f\n",
  531.                             (DEFAULT_ANIM_GAMMA));
  532.  fprintf(stderr,"       d#   Set gamma of display. Default %f\n",
  533.                             (DEFAULT_DISP_GAMMA));
  534.  fprintf(stderr,"\n  M[mopts]  Median-Cut SubMenu\n");
  535.  fprintf(stderr,"       a    compute box color from average of box.\n");
  536.  Usage_Default_TF( (DEFAULT_CMAP_MEDIAN_TYPE==CMAP_MEDIAN_SUM),1);
  537.  fprintf(stderr,"       c    compute box color as center of box.\n");
  538.  Usage_Default_TF( (DEFAULT_CMAP_MEDIAN_TYPE==CMAP_MEDIAN_CENTER),1);
  539.  fprintf(stderr,"       b#   Truncate rgb to # bits.\n");
  540.  Usage_Default_Num(CMAP_CACHE_MAX_BITS,1);
  541.  fprintf(stderr,"\n  S[sopts]  Scaling and Sizing SubMenu\n");
  542.  fprintf(stderr,"       i    Half the height of IFF anims if Interlaced.\n");
  543.  Usage_Default_TF(DEFAULT_ALLOW_LACE_FLAG,1);
  544.  fprintf(stderr,"       n    Prevents X11 window from resizing to match anim's size.\n"); 
  545.  Usage_Default_TF(DEFAULT_NORESIZE_FLAG,1);
  546.  fprintf(stderr,"       r    Allow user to resize anim on the fly.\n");
  547.  Usage_Default_TF(DEFAULT_ALLOW_RESIZING,1);
  548.  fprintf(stderr,"       s#   Scale size of anim by # before displaying.\n");
  549.  fprintf(stderr,"       h#   Scale width of anim by # before displaying.\n");
  550.  fprintf(stderr,"       v#   Scale height of anim by # before displaying.\n");
  551.  fprintf(stderr,"       x#   Scale anim to have width # before displaying.\n");
  552.  fprintf(stderr,"       y#   Scale anim to have height # before displaying.\n");
  553.  fprintf(stderr,"       c    Copy display scaling factors to buffer scaling factors\n");
  554.  fprintf(stderr,"       S#   Scale size of anim by # before buffering.\n");
  555.  fprintf(stderr,"       H#   Scale width of anim by # before buffering.\n");
  556.  fprintf(stderr,"       V#   Scale height of anim by # before buffering.\n");
  557.  fprintf(stderr,"       X#   Scale anim to have width # before buffering.\n");
  558.  fprintf(stderr,"       Y#   Scale anim to have height # before buffering.\n");
  559.  fprintf(stderr,"       C    Copy buffer scaling factors to display scaling factors\n");
  560.  fprintf(stderr,"\n  Normal Options\n");
  561.  fprintf(stderr,"       b    Uncompress and buffer images ahead of time.\n"); 
  562.  Usage_Default_TF(DEFAULT_BUFF_FLAG,1);
  563. #ifdef XSHM
  564.  fprintf(stderr,"       B    Use X11 Shared Memory Extention if supported.\n"); 
  565.  Usage_Default_TF(FALSE,1);
  566. #endif
  567.  fprintf(stderr,"       c    disable looping for nonlooping iff anims.\n"); 
  568.  Usage_Default_TF(DEFAULT_IFF_LOOP_OFF,1);
  569.  fprintf(stderr,"       d#   debug. 0(off) to 5(most) for level of detail.\n"); 
  570.  Usage_Default_Num(DEFAULT_DEBUG,1);
  571.  fprintf(stderr,"       F    Floyd-Steinberg dithering for Mono displays only.\n");
  572.  Usage_Default_TF(DEFAULT_DITHER_FLAG,1);
  573.  fprintf(stderr,"       f    Don't load anims into memory, but read from file as needed\n"); 
  574.  Usage_Default_TF(DEFAULT_BUFF_FLAG,1);
  575.  fprintf(stderr,"       j#   # is number of milliseconds between frames.\n");
  576.  fprintf(stderr,"         if 0 then default depends on the animation.\n");
  577.  Usage_Default_Num(DEFAULT_JIFFY_FLAG,1);
  578.  fprintf(stderr,"       l#   loop anim # times before moving on.\n");
  579.  Usage_Default_Num(DEFAULT_LOOPEACH_FLAG,1);
  580.  fprintf(stderr,"       lp#  ping-pong anim # times before moving on.\n");
  581.  Usage_Default_Num(DEFAULT_PINGPONG_FLAG,1);
  582.  fprintf(stderr,"       N    No display. Useful for benchmarking.\n");
  583.  fprintf(stderr,"       o    turns on certain optimizations. See readme.\n"); 
  584.  Usage_Default_TF(DEFAULT_OPTIMIZE_FLAG,1);
  585.  fprintf(stderr,"       p    Use Pixmap instead of Image in X11.\n"); 
  586.  Usage_Default_TF(DEFAULT_PIXMAP_FLAG,1);
  587.  fprintf(stderr,"       r    Allow color cycling for IFF single images.\n");
  588.  Usage_Default_TF(DEFAULT_CYCLE_IMAGE_FLAG,1);
  589.  fprintf(stderr,"       R    Allow color cycling for IFF anims.\n");
  590.  Usage_Default_TF(DEFAULT_CYCLE_ANIM_FLAG,1);
  591.  fprintf(stderr,"       T#   Title Option. See readme.\n");
  592.  fprintf(stderr,"       v    verbose mode.\n"); 
  593.  fprintf(stderr,"       V#   Use Visual #. # is obtained by +X option.\n"); 
  594.  fprintf(stderr,"       X    X11 verbose mode. Display Visual information.\n");
  595.  fprintf(stderr,"       Z    Have XAnim exit after playing cmd line.\n");
  596.  Usage_Default_TF(DEFAULT_VERBOSE,1);
  597.  fprintf(stderr,"\n");
  598.  fprintf(stderr,"Window commands.\n");
  599.  fprintf(stderr,"\n");
  600.  fprintf(stderr,"        q    quit.\n");
  601.  fprintf(stderr,"        Q    Quit.\n");
  602.  fprintf(stderr,"        g    Stop color cycling.\n");
  603.  fprintf(stderr,"        r    Restore original Colors(useful after g).\n");
  604.  fprintf(stderr,"    <space>  Toggle. Starts/Stops animation.\n");
  605.  fprintf(stderr,"        ,    Single step back one frame.\n");
  606.  fprintf(stderr,"        .    Single step forward one frame.\n");
  607.  fprintf(stderr,"        <    Go back to start of previous anim.\n");
  608.  fprintf(stderr,"        >    Go forward to start of next anim.\n");
  609.  fprintf(stderr,"        m    Single step back one frame staying within anim.\n");
  610.  fprintf(stderr,"        /    Single step forward one frame staying within anim.\n");
  611.  fprintf(stderr,"        -    Increase animation playback speed.\n");
  612.  fprintf(stderr,"        =    Decrease animation playback speed.\n");
  613.  fprintf(stderr,"        0    Reset animation playback speed to original values.\n");
  614.  fprintf(stderr,"\n");
  615.  fprintf(stderr,"Mouse Buttons.\n");
  616.  fprintf(stderr,"\n");
  617.  fprintf(stderr,"      <Left> Single step back one frame.\n");
  618.  fprintf(stderr,"    <Middle> Toggle. Starts/Stops animation.\n");
  619.  fprintf(stderr,"     <Right> Single step forward one frame.\n");
  620.  fprintf(stderr,"\n");
  621.  exit(0);
  622. }
  623.  
  624. #if MAIN
  625. int main(argc, argv)
  626. int argc;
  627. char *argv[];
  628. #else
  629. int xa_init()
  630. #endif
  631. {
  632.  char *filename,*in;
  633.  LONG i,j;
  634.  
  635. /* 
  636.  * Initialize global variables.
  637.  */
  638.  #if XWIN
  639.  theDisp = NULL;
  640. #endif
  641.  
  642.  cmap_color_func = 4;
  643.  cmap_sample_cnt = 5; /* default value */
  644.  
  645. #ifdef XSHM
  646.  im0_shminfo.shmaddr = 0;
  647.  im1_shminfo.shmaddr = 0;
  648.  im2_shminfo.shmaddr = 0;
  649. #endif
  650.  im_buff0 = im_buff1 = im_buff2 = im_buff3 = 0;
  651.  xa_disp_buff = 0;
  652.  xa_disp_buff_size = 0;
  653.  xa_scale_row_buff = 0;
  654.  xa_scale_row_size = 0;
  655.  xa_scale_buff    = 0;
  656.  xa_scale_buff_size = 0;
  657.  xa_imagex    = 0;
  658.  xa_imagey    = 0;
  659.  xa_disp_x    = 0;
  660.  xa_disp_y    = 0;
  661.  xa_scalex    = 1.0;
  662.  xa_scaley    = 1.0;
  663.  xa_buff_x    = 0;
  664.  xa_buff_y    = 0;
  665.  xa_bscalex    = 1.0;
  666.  xa_bscaley    = 1.0;
  667.  xa_need_to_scale_b = 0;
  668.  xa_need_to_scale_u = 0;
  669.  xa_max_imagex    = 0;
  670.  xa_max_imagey    = 0;
  671.  xa_max_disp_x    = 0;
  672.  xa_max_disp_y    = 0;
  673.  xa_anim_flags        = 0;
  674.  xa_merged_anim_flags    = 0;
  675.  x11_pack_flag    = FALSE;
  676.  x11_expose_flag = FALSE;
  677.  x11_error_possible = 0;
  678.  
  679.  first_file = cur_file = 0;
  680.  xa_file_num = -1;
  681.  
  682.  xa_anim_holdoff    = TRUE;
  683.  xa_anim_status        = XA_UNSTARTED;
  684.  xa_anim_ready        = FALSE;
  685.  
  686.  xa_fd            = -1;
  687.  xa_codec_buf        = 0;
  688.  xa_buffer_flag        = DEFAULT_BUFF_FLAG;
  689.  if (xa_buffer_flag == TRUE) xa_file_flag = FALSE;
  690.  else xa_file_flag    = DEFAULT_FILE_FLAG;
  691.  x11_shared_flag    = TRUE;
  692.  xa_pack_flag        = DEFAULT_PACK_FLAG;
  693.  xa_noresize_flag    = DEFAULT_NORESIZE_FLAG;
  694.  xa_verbose        = DEFAULT_VERBOSE;
  695.  xa_debug        = DEFAULT_DEBUG;
  696.  xa_anim_cycling    = DEFAULT_CYCLE_ANIM_FLAG;
  697.  xa_allow_lace        = DEFAULT_ALLOW_LACE_FLAG;
  698.  xa_allow_resizing    = DEFAULT_ALLOW_RESIZING;
  699.  xa_optimize_flag    = DEFAULT_OPTIMIZE_FLAG;
  700.  xa_pixmap_flag        = DEFAULT_PIXMAP_FLAG;
  701.  xa_dither_flag        = DEFAULT_DITHER_FLAG;
  702.  xa_loop_each_flag    = DEFAULT_LOOPEACH_FLAG;
  703.  xa_pingpong_flag    = DEFAULT_PINGPONG_FLAG;
  704.  xa_jiffy_flag        = DEFAULT_JIFFY_FLAG;
  705.  xa_speed_scale        = 0x01 << 16;
  706.  x11_verbose_flag    = DEFAULT_X11_VERBOSE_FLAG;
  707.  x11_kludge_1        = FALSE;
  708.  cmap_luma_sort        = DEFAULT_CMAP_LUMA_SORT;
  709.  cmap_map_to_1st_flag    = DEFAULT_CMAP_MAP_TO_1ST;
  710.  cmap_map_to_one_flag    = DEFAULT_CMAP_MAP_TO_ONE;
  711.  cmap_play_nice        = DEFAULT_CMAP_PLAY_NICE;
  712.  cmap_force_load    = FALSE;
  713.  xa_allow_nice        = TRUE;
  714.  cmap_hist_flag        = DEFAULT_CMAP_HIST_FLAG;
  715.  cmap_dither_type    = DEFAULT_CMAP_DITHER_TYPE;
  716.  
  717.  cmap_median_type    = DEFAULT_CMAP_MEDIAN_TYPE;
  718.  cmap_median_bits    = 6;
  719.  cmap_use_combsort    = TRUE;
  720.  cmap_floyd_error    = 256; 
  721.  cmap_cache        = 0;
  722.  cmap_cache_size    = 0;
  723.  cmap_cache_bits    = 0;
  724.  cmap_cache_rmask    = 0;
  725.  cmap_cache_gmask    = 0;
  726.  cmap_cache_bmask    = 0;
  727.  cmap_cache_chdr    = 0;
  728.  xa_disp_gamma        = DEFAULT_DISP_GAMMA;
  729.  xa_anim_gamma        = DEFAULT_ANIM_GAMMA;
  730.  xa_gamma_flag        = FALSE;
  731.  
  732.  xa_title_flag        = DEFAULT_XA_TITLE_FLAG;
  733.  xa_exit_flag        = DEFAULT_XA_EXIT_FLAG;
  734.  
  735.  xa_chdr_start        = 0;
  736.  xa_chdr_cur        = 0;
  737.  xa_chdr_now        = 0;
  738.  xa_chdr_first        = 0;
  739.  xa_cmap        = 0;
  740.  xa_cmap_size        = 0;
  741.  xa_cmap_off        = 0;
  742.  xa_map            = 0;
  743.  xa_map_size        = 0;
  744.  xa_map_off        = 0;
  745.  xa_time_start        = 0;
  746.  xa_time_end        = 0;
  747.  xa_time_av         = 0;
  748.  xa_time_num        = 0;
  749.  xa_no_disp        = FALSE;
  750.  xa_time_flag        = FALSE;
  751.  pod_max_colors        = 0;
  752.  xa_r_shift = xa_g_shift = xa_b_shift = 0;
  753.  xa_r_mask = xa_g_mask = xa_b_mask = 0;
  754.  xa_gray_bits = xa_gray_shift = 0;
  755.  xa_ham_map_size = 0;
  756.  xa_ham_map = 0;
  757.  xa_ham_chdr = 0;
  758.  xa_ham_init = 0;
  759.  fli_pad_kludge = FALSE;
  760.  xa_pause_hdr = 0;
  761.  
  762.  XA_Time_Init();
  763.  xa_gamma_flag = CMAP_Gamma_Adjust(xa_gamma_adj,xa_disp_gamma,xa_anim_gamma);
  764.  
  765.  if (DEFAULT_IFF_LOOP_OFF  == TRUE) xa_anim_flags |= ANIM_NOLOOP;
  766.  if (DEFAULT_CYCLE_IMAGE_FLAG == TRUE) xa_anim_flags |= ANIM_CYCLE;
  767.  
  768. /* What REV are we running
  769.  fprintf(stderr,"XAnim Rev %2.2f.%ld by Mark Podlipec (c) 1991-1994\n",DA_REV,DA_MINOR_REV);
  770.  */
  771.  
  772. /* quick command line check.
  773.  */
  774. #if MAIN
  775.  if (argc<2) Usage_Quick();
  776.  
  777. /* setup for dying time.
  778.  */
  779.  signal(SIGINT,Hard_Death);
  780.  
  781.  /* pre-check for user visual */
  782.  xa_user_visual = -1;
  783.  xa_user_class  = -1;
  784.  for(i=1;i<argc;i++)
  785.  {
  786.    in = argv[i];
  787.  
  788.    if ( ((in[0]=='-') || (in[0]=='+')) && (in[1]=='V') )
  789.    {
  790.      if ( (in[2] >= '0') && (in[2] <= '9') )  /* number */
  791.         xa_user_visual = atoi(&in[2]);
  792.      else    xa_user_class = XA_Get_Class( &in[2] );
  793.    }
  794.    else if ( (in[0]=='-') && (in[1]=='X') ) x11_verbose_flag = FALSE;
  795.    else if ( (in[0]=='+') && (in[1]=='X') ) x11_verbose_flag = TRUE;
  796.    else if ( (in[0]=='+') && (in[1]=='B') ) x11_shared_flag = TRUE;
  797.    else if ( (in[0]=='+') && (in[1]=='P') )
  798.    {
  799.      pod_max_colors = atoi(&in[2]); /* POD Testing only */
  800.    }
  801.  }
  802. #endif
  803.  
  804.  /* PreSet of X11 Display to find out what we're dealing with
  805.   */
  806. #if MAIN
  807.  X11_Pre_Setup(&argc, argv, xa_user_visual, xa_user_class);
  808. #else
  809.  X11_Pre_Setup(NULL, NULL, xa_user_visual, xa_user_class);
  810. #endif
  811.  if (xa_allow_nice == FALSE) cmap_play_nice = FALSE;
  812.  
  813.  /* Visual Dependent switches and flags */
  814.  if (x11_display_type & XA_X11_TRUE)
  815.  {
  816.    cmap_true_to_332  = FALSE; cmap_true_to_gray = FALSE;
  817.    cmap_true_to_1st  = FALSE; cmap_true_to_all  = FALSE;
  818.    cmap_true_map_flag = FALSE;
  819.  }
  820.  else if (x11_display_type & XA_X11_COLOR)
  821.  {
  822.    cmap_true_to_332  = DEFAULT_TRUE_TO_332;
  823.    cmap_true_to_gray = DEFAULT_TRUE_TO_GRAY;
  824.    cmap_true_to_1st  = DEFAULT_TRUE_TO_1ST;
  825.    cmap_true_to_all  = DEFAULT_TRUE_TO_ALL;
  826.    if (cmap_true_to_1st || cmap_true_to_all) cmap_true_map_flag = TRUE;
  827.    else cmap_true_map_flag = DEFAULT_TRUE_MAP_FLAG;
  828.  }
  829.  else { cmap_true_to_332  = FALSE; cmap_true_to_gray = TRUE; 
  830.         cmap_true_to_1st  = FALSE; cmap_true_to_all  = FALSE;
  831.         cmap_true_map_flag = FALSE;  }
  832.  
  833.  xa_time_start = XA_Time_Read();
  834.  
  835. /* Parse command line.
  836.  */
  837. #if MAIN
  838.  for(i=1; i < argc; i++)
  839.  {
  840.    in = argv[i];
  841.    if ( (in[0] == '-') || (in[0] == '+') )
  842.    {
  843.      LONG len,opt_on;
  844.  
  845.      if (in[0] == '-') opt_on = FALSE;
  846.      else opt_on = TRUE;
  847.      /* if + turns off then reverse opt_on */
  848.      if (DEFAULT_PLUS_IS_ON == FALSE) opt_on = (opt_on==TRUE)?FALSE:TRUE;
  849.  
  850.      len = strlen(argv[i]);
  851.      j = 1;
  852.      while( (j < len) && (in[j] != 0) )
  853.      {
  854.        switch(in[j])
  855.        {
  856.         case 'C':   /* colormap options sub menu */
  857.       {
  858.         ULONG exit_flag = FALSE;
  859.         j++;
  860.         while( (exit_flag == FALSE) && (j<len) )
  861.         {
  862.         switch(in[j])
  863.         {
  864.           case 's':
  865.             j++; cmap_sample_cnt = XA_Read_Int(in,&j);
  866.             break;
  867.           case 'F':
  868.             j++; cmap_color_func = XA_Read_Int(in,&j);
  869.             break;
  870.           case '1':
  871.              if (   (x11_display_type & XA_X11_TRUE)
  872.                  || (x11_display_type & XA_MONOCHROME) ) 
  873.                             opt_on = FALSE;
  874.             cmap_true_to_1st  = opt_on;
  875.             if (cmap_true_to_1st == TRUE)
  876.             {
  877.               cmap_true_to_gray = FALSE; cmap_true_to_332  = FALSE;
  878.               cmap_true_to_all  = FALSE; cmap_true_map_flag = TRUE;
  879.             }
  880.             j++; break;
  881.           case 'A':
  882.              if (   (x11_display_type & XA_X11_TRUE)
  883.                  || (x11_display_type & XA_MONOCHROME) ) 
  884.                             opt_on = FALSE;
  885.             cmap_true_to_all  = opt_on;
  886.             if (cmap_true_to_all == TRUE)
  887.             {
  888.               cmap_true_to_gray = FALSE; cmap_true_to_332  = FALSE;
  889.               cmap_true_to_1st  = FALSE; cmap_true_map_flag = TRUE;
  890.             }
  891.             j++; break;
  892.           case '3':
  893.              if (   (x11_display_type & XA_X11_TRUE)
  894.                  || (!(x11_display_type & XA_X11_COLOR))
  895.                  || (x11_display_type & XA_MONOCHROME) ) 
  896.                             opt_on = FALSE;
  897.             cmap_true_to_332  = opt_on;
  898.             if (opt_on == TRUE)
  899.             {
  900.               cmap_true_to_gray = FALSE; cmap_true_to_1st  = FALSE;
  901.               cmap_true_to_all  = FALSE;
  902.             }
  903.             j++; break;
  904.           case 'g':
  905.              if (x11_display_type & XA_X11_TRUE) opt_on = FALSE;
  906.             cmap_true_to_gray  = opt_on;
  907.             if (opt_on == TRUE)
  908.             {
  909.               cmap_true_to_332 = FALSE; cmap_true_to_1st = FALSE;
  910.               cmap_true_to_all = FALSE;
  911.             }
  912.             j++; break;
  913.           case 'a': cmap_map_to_one_flag = opt_on; j++; break;
  914.           case 'c': cmap_force_load = opt_on; j++; break;
  915.           case 'd': cmap_dither_type = CMAP_DITHER_FLOYD; j++; break;
  916.           case 'l': cmap_luma_sort  = opt_on; j++; break;
  917.           case 'f': cmap_map_to_1st_flag = opt_on; j++; break;
  918.           case 'm': cmap_true_map_flag = opt_on; j++; break;
  919.           case 'n': j++;
  920.             if (xa_allow_nice == TRUE) cmap_play_nice  = opt_on;
  921.             break;
  922.           case 'h': cmap_hist_flag  = opt_on; j++; break;
  923.           default: exit_flag = TRUE;
  924.         }
  925.         }
  926.       }
  927.           break;
  928.     case 'G': /* gamma options sub-menu */ 
  929.       {
  930.         ULONG exit_flag = FALSE;
  931.         j++;
  932.         while( (exit_flag == FALSE) && (j<len) )
  933.         {
  934.         switch(in[j])
  935.         {
  936.           case 'a': /* set anim gamma */
  937.             j++;
  938.             xa_anim_gamma = XA_Read_Float(in,&j);
  939.             if (xa_anim_gamma <= 0.0001) xa_anim_gamma = 0.0;
  940.             xa_gamma_flag = CMAP_Gamma_Adjust(xa_gamma_adj,
  941.                         xa_disp_gamma,xa_anim_gamma);
  942.             break;
  943.           case 'd': /* set display gamma */
  944.             j++;
  945.             xa_disp_gamma = XA_Read_Float(in,&j);
  946.             if (xa_disp_gamma <= 0.0001) xa_disp_gamma = 0.0;
  947.             xa_gamma_flag = CMAP_Gamma_Adjust(xa_gamma_adj,
  948.                         xa_disp_gamma,xa_anim_gamma);
  949.             break;
  950.           default: exit_flag = TRUE;
  951.         }
  952.         }
  953.       }
  954.           break;
  955.  
  956.     case 'M': /* median cut options sub-menu */ 
  957.       {
  958.         ULONG exit_flag = FALSE;
  959.         j++;
  960.         while( (exit_flag == FALSE) && (j<len) )
  961.         {
  962.         switch(in[j])
  963.         {
  964.           case 'a': cmap_median_type = CMAP_MEDIAN_SUM; j++; break;
  965.           case 'c': cmap_median_type = CMAP_MEDIAN_CENTER; j++; break;
  966.           /* POD Testing only */
  967.           case 'e':
  968.             j++; cmap_floyd_error = XA_Read_Int(in,&j);
  969.             if (cmap_floyd_error <= 0) cmap_floyd_error = 0;
  970.             break;
  971.           case 'b':
  972.             j++; cmap_median_bits = XA_Read_Int(in,&j);
  973.             if (cmap_median_bits <= 5) cmap_median_bits = 5;
  974.             if (cmap_median_bits >  8) cmap_median_bits = 8;
  975.             break;
  976.           /* POD benchmark only */
  977.           case 'q': if (opt_on == TRUE) cmap_use_combsort = FALSE;
  978.                 else cmap_use_combsort = TRUE;
  979.                 j++; break;
  980.           default: exit_flag = TRUE;
  981.         }
  982.         }
  983.       }
  984.           break;
  985.         case 'B':
  986.                 x11_shared_flag = opt_on;    j++;
  987.                 break;
  988.         case 'b':
  989.                 xa_buffer_flag = opt_on;    j++;
  990.         if (xa_buffer_flag==TRUE) xa_file_flag = FALSE;
  991.                 break;
  992.         case 'c':
  993.                 if (opt_on==TRUE) xa_anim_flags |= ANIM_NOLOOP;
  994.                 else xa_anim_flags &= (~ANIM_NOLOOP);
  995.                 j++; break;
  996.         case 'd':
  997.                 j++; xa_debug = XA_Read_Int(in,&j);
  998.                 if (xa_debug <= 0) xa_debug = 0;
  999.         break;
  1000.         case 'f':
  1001.                 xa_file_flag = opt_on;    j++;
  1002.         if (xa_file_flag==TRUE) xa_buffer_flag = FALSE;
  1003.         break;
  1004.         case 'F':
  1005.                 xa_dither_flag = opt_on;    j++;    break;
  1006.         case 'h':
  1007.                 Usage(); break;
  1008.     case 'J': 
  1009.         j++; xa_speed_scale = XA_Read_Int(in,&j);
  1010.         if (xa_speed_scale == 0) xa_speed_scale = 1;
  1011.         if (xa_speed_scale > 1000) xa_speed_scale = 1000;
  1012.         if (opt_on == TRUE) xa_speed_scale <<= 16;
  1013.         else    xa_speed_scale = (0x01 << 16) / xa_speed_scale;
  1014.         break;
  1015.         case 'j':
  1016.                 j++;
  1017.         if ( (in[j] >= '0') || (in[j] <= '9') )
  1018.         { 
  1019.                   xa_jiffy_flag = XA_Read_Int(in,&j);
  1020.                   if (xa_jiffy_flag <= 0) xa_jiffy_flag = 1;
  1021.         }
  1022.         else xa_jiffy_flag = 0; /* off */
  1023.                 break;
  1024.         case 'k':
  1025.         { ULONG tmp;
  1026.                   j++;
  1027.           if ( (in[j] >= '0') || (in[j] <= '9') )
  1028.           { 
  1029.                     tmp = XA_Read_Int(in,&j);
  1030.                     if (tmp==1) fli_pad_kludge = opt_on;
  1031.           }
  1032.         }
  1033.                 break;
  1034.         case 'l':
  1035.         j++; 
  1036.         if (in[j] == 'p')
  1037.         {
  1038.           xa_pingpong_flag = opt_on; j++;
  1039.         }
  1040.         else xa_pingpong_flag = FALSE;
  1041.                 xa_loop_each_flag = XA_Read_Int(in,&j);
  1042.                 if (xa_loop_each_flag<=0) xa_loop_each_flag = 1;
  1043.         break;
  1044.         case 'N':
  1045.         xa_no_disp = opt_on;
  1046.                 xa_time_flag = opt_on;    j++;    break;
  1047.         case 'o':
  1048.                 xa_optimize_flag = opt_on; j++;    break;
  1049.         case 'p':
  1050.                 xa_pixmap_flag = opt_on; j++;
  1051.         if (opt_on==TRUE) xa_anim_flags |= ANIM_PIXMAP;
  1052.         else xa_anim_flags &= ~ANIM_PIXMAP;
  1053.                 break;
  1054.         case 'P':
  1055.                 j++; pod_max_colors = XA_Read_Int(in,&j);
  1056.                 if (pod_max_colors <= 0) pod_max_colors = 0;
  1057.         break;
  1058.         case 'r':
  1059.                 if (opt_on == TRUE)    xa_anim_flags |= ANIM_CYCLE;
  1060.                 else            xa_anim_flags &= (~ANIM_CYCLE);
  1061.                 j++;
  1062.                 break;
  1063.         case 'R':
  1064.                 xa_anim_cycling = opt_on; j++;    break;
  1065.         case 'S':
  1066.       {
  1067.         ULONG exit_flag = FALSE;
  1068.         j++;
  1069.         while( (exit_flag==FALSE) && (j<len) )
  1070.         {
  1071.         switch(in[j])
  1072.         {
  1073.           case 'i': xa_allow_lace = opt_on;  j++; break;
  1074.           case 'n': xa_noresize_flag = opt_on;  j++; break;
  1075.           case 'r': xa_allow_resizing = opt_on; j++; break;
  1076.           case 'c': /* copy display scaling to buffer scaling */
  1077.             j++;
  1078.             xa_bscalex = xa_scalex; xa_bscaley = xa_scaley;
  1079.             xa_buff_x = xa_disp_x; xa_buff_y = xa_disp_y;
  1080.             break;
  1081.           case 's': /* scale anim display size */
  1082.             j++;
  1083.                     xa_scalex = XA_Read_Float(in,&j);
  1084.             if (xa_scalex == 0.0) xa_scalex = 1.0;
  1085.             xa_scaley = xa_scalex;
  1086.             xa_disp_x = xa_disp_y = 0; break;
  1087.           case 'x':  /* set anim display x size */
  1088.             j++; xa_scalex = 1.0;
  1089.                     xa_disp_x = XA_Read_Int(in,&j);
  1090.             break;
  1091.           case 'y':  /* set anim display y size */
  1092.             j++; xa_scaley = 1.0;
  1093.                     xa_disp_y = XA_Read_Int(in,&j);
  1094.             break;
  1095.           case 'h':  /* scale anim display horizontally */
  1096.             j++;
  1097.                     xa_scalex = XA_Read_Float(in,&j);
  1098.             if (xa_scalex == 0.0) xa_scalex = 1.0;
  1099.             xa_disp_x = 0; break;
  1100.           case 'v':  /* scale anim display vertically */
  1101.             j++;
  1102.                     xa_scaley = XA_Read_Float(in,&j);
  1103.             if (xa_scaley == 0.0) xa_scaley = 1.0;
  1104.             xa_disp_y = 0; break;
  1105.           case 'C': /* copy buffer scaling to display scaling */
  1106.             j++;
  1107.             xa_scalex = xa_bscalex; xa_scaley = xa_bscaley;
  1108.             xa_disp_x = xa_buff_x; xa_disp_y = xa_buff_y;
  1109.             break;
  1110.           case 'S': /* scale anim buffering size */
  1111.             j++;
  1112.                     xa_bscalex = XA_Read_Float(in,&j);
  1113.             if (xa_bscalex == 0.0) xa_bscalex = 1.0;
  1114.             xa_bscaley = xa_bscalex;
  1115.             xa_buff_x = xa_buff_y = 0; break;
  1116.           case 'X':  /* set anim buffering x size */
  1117.             j++; xa_bscalex = 1.0;
  1118.                     xa_buff_x = XA_Read_Int(in,&j);
  1119.             break;
  1120.           case 'Y':  /* set anim buffering y size */
  1121.             j++; xa_bscaley = 1.0;
  1122.                     xa_buff_y = XA_Read_Int(in,&j);
  1123.             break;
  1124.           case 'H':  /* scale anim buffering horizontally */
  1125.             j++;
  1126.                     xa_bscalex = XA_Read_Float(in,&j);
  1127.             if (xa_bscalex == 0.0) xa_bscalex = 1.0;
  1128.             xa_buff_x = 0; break;
  1129.           case 'V':  /* scale anim buffering vertically */
  1130.             j++;
  1131.                     xa_bscaley = XA_Read_Float(in,&j);
  1132.             if (xa_bscaley == 0.0) xa_bscaley = 1.0;
  1133.             xa_buff_y = 0; break;
  1134.           default: exit_flag = TRUE;
  1135.         }
  1136.         }
  1137.       }
  1138.       break;
  1139.         case 't':
  1140.                 xa_time_flag = opt_on;    j++;    break;
  1141.         case 'T':
  1142.                 j++; xa_title_flag = XA_Read_Int(in,&j);
  1143.                 if (xa_title_flag > 2) xa_title_flag = 2;
  1144.         break;
  1145.         case 'v':
  1146.                 xa_verbose = opt_on;    j++;    break;
  1147.         case 'X':
  1148.         X11_Show_Visuals();    j++;    break;
  1149.         case 'V':
  1150.         j += len; break;   /* ignore reset and move on */
  1151.         case 'Z':
  1152.       {
  1153.         ULONG exit_flag = FALSE;
  1154.         j++;
  1155.         while( (exit_flag==FALSE) && (j<len) )
  1156.         { ULONG tmp;
  1157.         switch(in[j])
  1158.         {
  1159.           case 'e': xa_exit_flag = opt_on;      j++;    break;
  1160.           case 'p':
  1161.             j++; tmp = XA_Read_Int(in,&j);
  1162.             XA_Add_Pause(tmp);
  1163.             break;
  1164.         }
  1165.         }
  1166.       }
  1167.       break;
  1168.         case '-':
  1169.                 opt_on = (DEFAULT_PLUS_IS_ON==TRUE)?FALSE:TRUE; j++;    break;
  1170.         case '+':
  1171.                 opt_on = (DEFAULT_PLUS_IS_ON==TRUE)?TRUE:FALSE; j++;    break;
  1172.         default:
  1173.                 Usage_Quick();
  1174.        } /* end of option switch */
  1175.      } /* end of loop through options */
  1176.    } /* end of if - */
  1177.    else 
  1178.    /* If no hyphen in front of argument, assume it's a file.
  1179.     */
  1180.    { ULONG result;
  1181.      filename = argv[i];
  1182.  
  1183.      /* Visual Dependent switches and flags */
  1184.      if (x11_display_type & XA_X11_TRUE)
  1185.      {
  1186.        cmap_true_to_332  = cmap_true_to_gray = FALSE;
  1187.        cmap_true_to_1st  = cmap_true_to_all  = cmap_true_map_flag = FALSE;
  1188.      }
  1189.      else if (!(x11_display_type & XA_X11_COLOR))
  1190.      { cmap_true_to_gray = TRUE; cmap_true_to_332  = FALSE;
  1191.        cmap_true_to_1st  = cmap_true_to_all  = cmap_true_map_flag = FALSE;
  1192.      }
  1193.     
  1194.      if ( (x11_display_type == XA_MONOCHROME) || (xa_pack_flag == TRUE) )
  1195.        xa_use_depth_flag = FALSE;
  1196.      else
  1197.        xa_use_depth_flag = TRUE;
  1198.         /* default is FLI  */
  1199.      cur_file = Get_Anim_Hdr(cur_file,filename);
  1200.      xa_anim_type = Determine_Anim_Type(filename);
  1201.      cur_file->anim_type = xa_anim_type;
  1202.      cur_file->anim_flags = xa_anim_flags;
  1203.      if (x11_display_type == XA_MONOCHROME) xa_optimize_flag = FALSE;
  1204.      switch(xa_anim_type)
  1205.      {
  1206.         case IFF_ANIM:
  1207.       if (xa_verbose) fprintf(stderr,"Reading IFF File %s\n",filename);
  1208.       result = IFF_Read_File(filename,cur_file);
  1209.       break;
  1210.         case GIF_ANIM:
  1211.       if (xa_verbose) fprintf(stderr,"Reading GIF File %s\n",filename);
  1212.       result = GIF_Read_Anim(filename,cur_file);
  1213.       break;
  1214.         case TXT_ANIM:
  1215.       if (xa_verbose) fprintf(stderr,"Reading TXT File %s\n",filename);
  1216.       result = TXT_Read_File(filename,cur_file);
  1217.       break;
  1218.         case FLI_ANIM:
  1219.       if (xa_verbose) fprintf(stderr,"Reading FLI File %s\n",filename);
  1220.       result = Fli_Read_File(filename,cur_file);
  1221.       break;
  1222.         case DL_ANIM:
  1223.       if (xa_verbose) fprintf(stderr,"Reading DL File %s\n",filename);
  1224.       result = DL_Read_File(filename,cur_file);
  1225.       break;
  1226.         case PFX_ANIM:
  1227.       if (xa_verbose) fprintf(stderr,"Reading PFX File %s\n",filename);
  1228.       result = PFX_Read_File(filename,cur_file);
  1229.       break;
  1230. #if SETFILE
  1231.         case SET_ANIM:
  1232.       if (xa_verbose) fprintf(stderr,"Reading SET File %s\n",filename);
  1233.       result = SET_Read_File(filename,cur_file);
  1234.       break;
  1235. #endif
  1236.         case RLE_ANIM:
  1237.       if (xa_verbose) fprintf(stderr,"Reading RLE File %s\n",filename);
  1238.       result = RLE_Read_File(filename,cur_file);
  1239.       break;
  1240.         case AVI_ANIM:
  1241.       if (xa_verbose) fprintf(stderr,"Reading AVI File %s\n",filename);
  1242.       result = AVI_Read_File(filename,cur_file);
  1243.       break;
  1244.         case QT_ANIM:
  1245.       if (xa_verbose) fprintf(stderr,"Reading QT File %s\n",filename);
  1246.       result = QT_Read_File(filename,cur_file);
  1247.       break;
  1248.         case NOFILE_ANIM:
  1249.       fprintf(stderr,"File %s not found\n",filename);
  1250.       result = FALSE;
  1251.       break;
  1252.         default:
  1253.       fprintf(stderr,"Unknown or unsupported animation type: %s\n",
  1254.                                 filename);
  1255.       result = FALSE;
  1256.       break;
  1257.       } 
  1258.       if (result == FALSE) cur_file = Return_Anim_Hdr(cur_file);
  1259.       else
  1260.       { ULONG tmpx,tmpy;
  1261.         /* Setup up anim header.  */
  1262.         cur_file->loop_num = xa_loop_each_flag;
  1263.  
  1264.     cur_file->pause_lst = xa_pause_hdr;
  1265.     xa_pause_hdr = 0;
  1266.  
  1267.     xa_imagex = cur_file->imagex;
  1268.     xa_imagey = cur_file->imagey;
  1269.     if (xa_imagex > xa_max_imagex) xa_max_imagex = xa_imagex;
  1270.     if (xa_imagey > xa_max_imagey) xa_max_imagey = xa_imagey;
  1271.  
  1272.     /* Handle Buffer Scaling Here */
  1273.     if ( (xa_buff_x != 0) && (xa_buff_y != 0) )
  1274.         {tmpx = xa_buff_x; tmpy = xa_buff_y;}
  1275.     else if (xa_buff_x != 0) /* if just x, then adjust y */
  1276.         {tmpx = xa_buff_x; tmpy = (xa_imagey * xa_buff_x) / xa_imagex;}
  1277.     else if (xa_buff_y != 0) /* if just y, then adjust x */
  1278.         {tmpy = xa_buff_y; tmpx = (xa_imagex * xa_buff_y) / xa_imagey;}
  1279.     else
  1280.     {
  1281.         /* handle any scaling */
  1282.       tmpx = (ULONG)((float)(xa_imagex) * xa_bscalex);
  1283.       if (tmpx == 0) tmpx = xa_imagex;
  1284.       tmpy = (ULONG)((float)(xa_imagey) * xa_bscaley);
  1285.       if (tmpy == 0) tmpy = xa_imagey;
  1286.     }
  1287.     cur_file->buffx = tmpx;
  1288.     cur_file->buffy = tmpy;
  1289.  
  1290.         /* Handle Display Scaling Here */
  1291.     if ( (xa_disp_x != 0) && (xa_disp_y != 0) ) 
  1292.         {tmpx = xa_disp_x; tmpy = xa_disp_y;}
  1293.     else if (xa_disp_x != 0) /* if just x, then adjust y */
  1294.         {tmpx = xa_disp_x; tmpy = (xa_imagey * xa_disp_x) / xa_imagex;}
  1295.     else if (xa_disp_y != 0) /* if just y, then adjust x */
  1296.         {tmpy = xa_disp_y; tmpx = (xa_imagex * xa_disp_y) / xa_imagey;}
  1297.     else
  1298.     {
  1299.         /* handle any scaling */
  1300.       tmpx = (ULONG)((float)(xa_imagex) * xa_scalex);
  1301.       if (tmpx == 0) tmpx = xa_imagex;
  1302.       tmpy = (ULONG)((float)(xa_imagey) * xa_scaley);
  1303.       if (tmpy == 0) tmpy = xa_imagey;
  1304.     }
  1305.     /* handle any IFF laced images */
  1306.     if ( (xa_allow_lace==TRUE) && (cur_file->anim_flags & ANIM_LACE))
  1307.         tmpy >>= 1;
  1308.     else    cur_file->anim_flags &= ~ANIM_LACE;
  1309.     cur_file->dispx = tmpx;
  1310.     cur_file->dispy = tmpy;
  1311.     if (tmpx > xa_max_disp_x) xa_max_disp_x = tmpx;
  1312.     if (tmpy > xa_max_disp_y) xa_max_disp_y = tmpy;
  1313.  
  1314.     if ((cmap_dither_type == CMAP_DITHER_FLOYD) && (xa_buffer_flag==FALSE))
  1315.             cur_file->anim_flags |= ANIM_3RD_BUF;
  1316.     xa_merged_anim_flags |= cur_file->anim_flags;
  1317.  
  1318.     /* NOTE: removed fade, remember to readd eventually */
  1319.  
  1320.     if (xa_time_flag == TRUE)
  1321.     {
  1322.       LONG time_int;
  1323.       xa_time_end = XA_Time_Read();
  1324.       time_int = xa_time_end - xa_time_start;
  1325.       fprintf(stderr,"time = %ld\n",time_int);
  1326.       xa_time_start = XA_Time_Read();
  1327.     }
  1328.       } /* valid animation file */
  1329.     } /* end of read in file */
  1330.  } /* end of loopin through arguments */
  1331.  
  1332.  /* No anims listed
  1333.   */
  1334.  if (first_file == 0) Usage_Quick();
  1335.  
  1336. #if XWIN
  1337.  /* Set up X11 Display
  1338.   */
  1339.  
  1340.  if (xa_noresize_flag==TRUE) X11_Setup_Window(xa_max_disp_x,xa_max_disp_y,
  1341.         xa_max_disp_x,xa_max_disp_y);
  1342.  else X11_Setup_Window(xa_max_disp_x,xa_max_disp_y,
  1343.         first_file->dispx, first_file->dispy);
  1344.  if (x11_display_type == XA_MONOCHROME) xa_optimize_flag = FALSE;
  1345.  #endif
  1346.  
  1347.  /* color map manipulation */
  1348.  CMAP_Manipulate_CHDRS();
  1349.  /* Kludge for some X11 displays */
  1350.  if (x11_kludge_1 == TRUE) CMAP_Expand_Maps();
  1351.  
  1352.  xa_time_start = XA_Time_Read();
  1353.  cur_file = first_file;
  1354.  while(cur_file)
  1355.  {
  1356.    ACT_Make_Images(cur_file->acts);
  1357.    cur_file = cur_file->next_file;
  1358.    if (cur_file == first_file) cur_file = 0;
  1359.  }
  1360.  if (xa_time_flag == TRUE)
  1361.  {
  1362.    LONG time_int;
  1363.    xa_time_end = XA_Time_Read();
  1364.    time_int = xa_time_end - xa_time_start;
  1365.    fprintf(stderr,"ACT_Make_Images: time = %ld\n",time_int);
  1366.    xa_time_start = XA_Time_Read();
  1367.  }
  1368.  
  1369. #if XWIN
  1370.  /* Start off Animation.
  1371.   */
  1372.   ShowAnimation();
  1373.  /* Map window and then Wait for user input.
  1374.   */
  1375.   X11_Map_Window();
  1376.   xanim_events();
  1377. #endif
  1378.  /* Self-Explanatory
  1379.   */
  1380.   TheEnd();
  1381. #endif
  1382.   return(0);
  1383. }
  1384.  
  1385. /*
  1386.  * ShowAnimation allocates and sets up required image buffers and
  1387.  * initializes animation variables.
  1388.  * It then kicks off the animation.
  1389.  */
  1390. void ShowAnimation()
  1391. {
  1392.   xa_max_image_size = xa_max_imagex * xa_max_imagey;
  1393.   xa_max_disp_size = xa_max_disp_x * xa_max_disp_y;
  1394.   if (   (xa_merged_anim_flags & ANIM_SNG_BUF)
  1395.       || (xa_merged_anim_flags & ANIM_DBL_BUF) )
  1396.   {
  1397. #ifdef XSHM
  1398.     if (shm)
  1399.     {
  1400.       im0_Image = XShmCreateImage(theDisp,theVisual,x11_depth,
  1401.                 ZPixmap, 0, &im0_shminfo, xa_max_imagex, xa_max_imagey );
  1402.       im0_shminfo.shmid = shmget(IPC_PRIVATE, 
  1403.         xa_max_image_size * x11_bytes_pixel, (IPC_CREAT | 0777 ));
  1404.       if (im0_shminfo.shmid < 0) { perror("shmget"); exit(0); }
  1405.       im0_shminfo.shmaddr = (char *) shmat(im0_shminfo.shmid, 0, 0);
  1406.       XSync(theDisp, False);
  1407.       x11_error_possible = 1;  /* if remote display. following will fail */
  1408.       XShmAttach(theDisp, &im0_shminfo);
  1409.       XSync(theDisp, False);
  1410.       if (x11_error_possible == -1) /* above failed - back off */
  1411.       {
  1412.     shm = 0;
  1413.     x11_error_possible = 0;
  1414.     if (xa_verbose) fprintf(stderr,"SHM Attach failed: backing off\n");
  1415.     shmdt(im0_shminfo.shmaddr);     im0_shminfo.shmaddr = 0;
  1416.     im0_Image->data = 0;
  1417.     XDestroyImage(im0_Image);       im0_Image = 0;
  1418.     im_buff0 = (char *) malloc(xa_max_image_size * x11_bytes_pixel);
  1419.     if (im_buff0 == 0) TheEnd1("ShowAnimation: im_buff0 malloc err0");
  1420.       }
  1421.       else
  1422.       {
  1423.         shmctl(im0_shminfo.shmid, IPC_RMID, 0 );
  1424.         im0_Image->data = im_buff0 = im0_shminfo.shmaddr;
  1425.         sh_Image = im0_Image;
  1426. DEBUG_LEVEL1 fprintf(stderr,"IM_BUFF0 = %lx im0_IMAGE = %lx\n",im_buff0,im0_Image);
  1427.       }
  1428.     } else
  1429. #endif /* XSHM */
  1430.     {
  1431.       im_buff0 = (char *) malloc(xa_max_image_size * x11_bytes_pixel);
  1432.       if (im_buff0 == 0) TheEnd1("ShowAnimation: im_buff0 malloc err0");
  1433.     }
  1434.     memset(im_buff0,0x00,(xa_max_image_size * x11_bytes_pixel) );  
  1435.   }
  1436.   if (xa_merged_anim_flags & ANIM_DBL_BUF)
  1437.   {
  1438. #ifdef XSHM
  1439.     if (shm)
  1440.     {
  1441.       im1_Image = XShmCreateImage(theDisp,theVisual,x11_depth,
  1442.                 ZPixmap, 0, &im1_shminfo, xa_max_imagex, xa_max_imagey );
  1443.       im1_shminfo.shmid = shmget(IPC_PRIVATE, 
  1444.         xa_max_image_size * x11_bytes_pixel, (IPC_CREAT | 0777 ));
  1445.       if (im1_shminfo.shmid < 0) { perror("shmget"); exit(0); }
  1446.       im1_shminfo.shmaddr = (char *) shmat(im1_shminfo.shmid, 0, 0);
  1447.       XSync(theDisp, False);
  1448.       XShmAttach(theDisp, &im1_shminfo);
  1449.       XSync(theDisp, False);
  1450.       shmctl(im1_shminfo.shmid, IPC_RMID, 0 );
  1451.       im1_Image->data = im_buff1 = im1_shminfo.shmaddr;
  1452. DEBUG_LEVEL1 fprintf(stderr,"IM_BUFF1 = %lx im1_IMAGE = %lx\n",im_buff1,im1_Image);
  1453.     } else
  1454. #endif /* XSHM */
  1455.     {
  1456.       im_buff1 = (char *) malloc(xa_max_image_size);
  1457.       if (im_buff1 == False) TheEnd1("ShowAnimation: im_buff1 malloc err");
  1458.     }
  1459.   }
  1460.   if (xa_merged_anim_flags & ANIM_3RD_BUF)
  1461.   {
  1462. #ifdef XSHM
  1463.     if (shm)
  1464.     {
  1465.       im2_Image = XShmCreateImage(theDisp,theVisual,x11_depth,
  1466.                 ZPixmap, 0, &im2_shminfo, xa_max_imagex, xa_max_imagey );
  1467.       im2_shminfo.shmid = shmget(IPC_PRIVATE, 
  1468.         xa_max_image_size * x11_bytes_pixel, (IPC_CREAT | 0777 ));
  1469.       if (im2_shminfo.shmid < 0) { perror("shmget"); exit(0); }
  1470.       im2_shminfo.shmaddr = (char *) shmat(im2_shminfo.shmid, 0, 0);
  1471.       XSync(theDisp, False);
  1472.       XShmAttach(theDisp, &im2_shminfo);
  1473.       XSync(theDisp, False);
  1474.       shmctl(im2_shminfo.shmid, IPC_RMID, 0 );
  1475.       im2_Image->data = im_buff2 = im2_shminfo.shmaddr;
  1476. DEBUG_LEVEL2 fprintf(stderr,"IM_BUFF2 = %lx im2_IMAGE = %lx\n",im_buff2,im2_Image);
  1477.     } else
  1478. #endif /* XSHM */
  1479.     {
  1480.       im_buff2 = (char *) malloc(xa_max_image_size * x11_bytes_pixel);
  1481.       if (im_buff2 == 0) TheEnd1("ShowAnimation: im_buff2 malloc err1");
  1482.     }
  1483.   }
  1484.   if ( (x11_bits_per_pixel == 2) || (x11_bits_per_pixel == 4) )
  1485.   {
  1486.     ULONG tsize;
  1487.     ULONG pbb = (8 / x11_bits_per_pixel);
  1488.     tsize = (xa_max_imagex + pbb - 1) / pbb;
  1489.     im_buff3 = (char *) malloc(xa_max_disp_y * tsize);
  1490.     if (im_buff3 == 0) TheEnd1("ShowAnimation: im_buff3 malloc err1");
  1491.     x11_pack_flag = TRUE;
  1492.   }
  1493.   xa_pic = im_buff0;
  1494.   cur_file = first_file;
  1495.   cur_floop = 0;
  1496.   cur_frame = -1;  /* since we step first */
  1497.   file_is_started = FALSE;
  1498.   xa_cycle_cnt = 0;
  1499.   xa_now_cycling = FALSE;
  1500.  
  1501.   xa_anim_ready = TRUE; /* allow expose event to start animation */
  1502. }
  1503.  
  1504. #if XWIN
  1505. /*
  1506.  * This is the heart of this program. It does each action and then calls
  1507.  * itself with a timeout via the XtAppAddTimeOut call.
  1508.  */
  1509. void ShowAction(command,id)
  1510. ULONG command;
  1511. XtIntervalId *id;
  1512. {
  1513.  LONG t_frame_start,t_frame_end,t_frame_int;
  1514.  
  1515. /* just for benchmarking, currently isn't use */
  1516. /*
  1517. ShowAction_Loop:
  1518. */
  1519.  
  1520.  if (command == XA_SHOW_NORM)
  1521.  {
  1522.   switch (xa_anim_status)
  1523.   {
  1524.     case XA_BEGINNING:  
  1525.     if (xa_anim_ready == FALSE)
  1526.     { /* try again 10ms later */
  1527.       XtAppAddTimeOut(theContext,10, (XtTimerCallbackProc)ShowAction, 
  1528.                         (XtPointer)(XA_SHOW_NORM));
  1529.       return;
  1530.     }
  1531.     xa_anim_status = XA_RUN_NEXT; /* drop through */
  1532.     case XA_STEP_NEXT: 
  1533.     case XA_RUN_NEXT:   
  1534.     Step_Action_Next();
  1535.     break;
  1536.     case XA_STEP_PREV:
  1537.     case XA_RUN_PREV:   
  1538.     Step_Action_Prev();
  1539.     break;
  1540.     case XA_ISTP_NEXT: 
  1541.     Step_Frame_Next();
  1542.     break;
  1543.     case XA_ISTP_PREV: 
  1544.     Step_Frame_Prev();
  1545.     break;
  1546.     case XA_FILE_NEXT:
  1547.     Step_File_Next();
  1548.     xa_anim_status = XA_STEP_NEXT;
  1549.     break;
  1550.     case XA_FILE_PREV:
  1551.     Step_File_Prev();
  1552.     xa_anim_status = XA_STEP_PREV;
  1553.     break;
  1554.     case XA_UNSTARTED:  
  1555.     case XA_STOP_NEXT:  
  1556.     case XA_STOP_PREV:  
  1557.     if (xa_title_flag != XA_TITLE_NONE)
  1558.     {
  1559.       sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  1560.       XStoreName(theDisp,mainW,xa_title);
  1561.     }
  1562.     xa_anim_holdoff = FALSE;
  1563.     return;
  1564.     break;
  1565.     default:
  1566.     xa_anim_holdoff = FALSE;
  1567.     return;
  1568.     break;
  1569.   }
  1570.  }
  1571.  
  1572.   DEBUG_LEVEL1 fprintf(stderr,"frame = %ld\n",cur_frame);
  1573.  
  1574.  /* 1st throught this particular file.
  1575.   * Resize if necessary and init required variables.
  1576.   */
  1577.   if (file_is_started == FALSE)
  1578.   {
  1579.      /* If previous anim is still cycling, wait for it to stop */
  1580.     if (xa_now_cycling == TRUE)
  1581.     {
  1582.       xa_anim_flags &= ~(ANIM_CYCLE);
  1583.       XtAppAddTimeOut(theContext, 50, (XtTimerCallbackProc)XA_Cycle_Wait, 
  1584.                             (XtPointer)(NULL) );
  1585.       return; 
  1586.     }
  1587.  
  1588.     file_is_started = TRUE;
  1589.     xa_anim_flags = cur_file->anim_flags;
  1590.     if (xa_anim_flags & ANIM_PIXMAP) xa_pixmap_flag = TRUE;
  1591.     else xa_pixmap_flag = FALSE;
  1592.  
  1593.       /* user has not resized window yet */
  1594.     if (     (xa_allow_resizing == FALSE)
  1595.          || ( (xa_allow_resizing == TRUE) && (x11_window_x==0) )
  1596.        )
  1597.     {   /* anim if allowed to cause window resizing */
  1598.       if (xa_noresize_flag == FALSE)
  1599.       {
  1600.         if ((xa_disp_x != cur_file->dispx) || (xa_disp_y != cur_file->dispy)) 
  1601.         {
  1602. DEBUG_LEVEL1 fprintf(stderr,"resizing to <%ld,%ld>\n",cur_file->dispx,cur_file->dispy);
  1603.        XResizeWindow(theDisp,mainW,cur_file->dispx,cur_file->dispy);
  1604.        x11_window_x = cur_file->dispx; x11_window_y = cur_file->dispy;
  1605.            XSync(theDisp,False);
  1606.            XFlush(theDisp);
  1607.         }
  1608.       }
  1609.       else /* fixed window size */
  1610.       {
  1611.         if (xa_disp_x > cur_file->dispx)
  1612.         XClearArea(theDisp,mainW,cur_file->dispx,0, 0,0,FALSE);
  1613.         if (xa_disp_y > cur_file->dispy)
  1614.         XClearArea(theDisp,mainW,0,cur_file->dispy, 0,0,FALSE);
  1615.       }
  1616.     }
  1617.     /* Do Title if set */
  1618.     switch(xa_title_flag)
  1619.     { 
  1620.       case XA_TITLE_FILE:
  1621.     sprintf(xa_title,"XAnim: %s",cur_file->name);
  1622.     break;
  1623.       case XA_TITLE_FRAME:
  1624.     if (cur_frame >= 0)
  1625.          sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  1626.     else sprintf(xa_title,"XAnim: %s",cur_file->name);
  1627.     break;
  1628.       default:
  1629.     sprintf(xa_title,"XAnim");
  1630.     break;
  1631.     }
  1632.     XStoreName(theDisp,mainW,xa_title);
  1633.     /* Initialize variables
  1634.      */
  1635. #ifdef XSHM
  1636.     if (xa_anim_flags & ANIM_SNG_BUF) sh_Image = im0_Image;
  1637. #endif
  1638.     if (xa_anim_flags & ANIM_SNG_BUF) xa_pic = im_buff0; 
  1639.     xa_imagex = cur_file->imagex;
  1640.     xa_imagey = cur_file->imagey;
  1641.     xa_disp_x = cur_file->dispx;
  1642.     xa_disp_y = cur_file->dispy;
  1643.     xa_buff_x = cur_file->buffx;
  1644.     xa_buff_y = cur_file->buffy;
  1645.     xa_imaged = cur_file->imaged;
  1646.     xa_cmap_size = cur_file->imagec;
  1647.     xa_image_size = xa_imagex * xa_imagey;
  1648.     X11_Init_Image_Struct(theImage,xa_disp_x,xa_disp_y);
  1649.     if (xa_anim_flags & ANIM_USE_FILE)
  1650.     {
  1651.       if (xa_fd>=0) { close(xa_fd); xa_fd = -1; }
  1652.       if (xa_codec_buf) { FREE(xa_codec_buf,0x99); xa_codec_buf=0;}
  1653.       if ( (xa_fd=open(cur_file->fname,O_RDONLY,NULL)) == 0)
  1654.       { 
  1655.         fprintf(stderr,"can't open file %s for reading\n",cur_file->fname); 
  1656.         TheEnd();
  1657.       }
  1658.       xa_codec_buf = (char *)malloc( cur_file->max_fsize );
  1659.       if (xa_codec_buf==0) TheEnd1("malloc codec_buf err");
  1660.     }
  1661.     xa_pause_hdr = cur_file->pause_lst; 
  1662.     xa_time_start = XA_Time_Read();
  1663.   } /* end of file is not started */
  1664.  
  1665.  /* OK. A quick sanity check and then we act.
  1666.   */
  1667.  if ( (act = cur_file->frame_lst[cur_frame].act) != 0)
  1668.  {
  1669.     /* initialize act and get the current time.
  1670.      */
  1671.     t_frame_start = XA_Time_Read();
  1672.     t_frame_int = cur_file->frame_lst[cur_frame].time;
  1673.  
  1674.     if ( (xa_allow_resizing == TRUE) && (x11_window_x != 0) )
  1675.         { xa_disp_x = x11_window_x; xa_disp_y = x11_window_y; }
  1676.  
  1677.     if ((xa_disp_x != xa_buff_x) || (xa_disp_y != xa_buff_y))
  1678.      xa_need_to_scale_b = 1;
  1679.     else xa_need_to_scale_b = 0;
  1680.     if ((xa_disp_x != xa_imagex) || (xa_disp_y != xa_imagey))
  1681.      xa_need_to_scale_u = 1;
  1682.     else xa_need_to_scale_u = 0;
  1683.  
  1684.     /* lesdoit */
  1685.     switch(act->type)
  1686.     {
  1687.        /* 
  1688.         * NOP and DELAY don't change anything but can have timing info
  1689.         * that might prove useful. ie dramatic pauses :^)
  1690.         */
  1691.      case ACT_NOP:      
  1692.                         DEBUG_LEVEL2 fprintf(stderr,"ACT_NOP:\n");
  1693.                         break;
  1694.      case ACT_DELAY:    
  1695.                         DEBUG_LEVEL2 fprintf(stderr,"ACT_DELAY:\n");
  1696.                         break;
  1697.        /* 
  1698.         * Change Color Map.
  1699.         */
  1700.      case ACT_CMAP:     
  1701.         if (   (cmap_play_nice == FALSE) 
  1702.         && (!(x11_display_type & XA_X11_STATIC)) )
  1703.     { ColorReg *tcmap;
  1704.       LONG j;
  1705.       ACT_CMAP_HDR *cmap_hdr;
  1706.  
  1707.       cmap_hdr = (ACT_CMAP_HDR *)act->data;
  1708.       xa_cmap_size = cmap_hdr->csize;
  1709.       if (xa_cmap_size > x11_cmap_size) xa_cmap_size = x11_cmap_size;
  1710.       xa_cmap_off  = cmap_hdr->coff;
  1711.       tcmap      = (ColorReg *)cmap_hdr->data;
  1712.       for(j=0; j<xa_cmap_size;j++)
  1713.       {
  1714.         xa_cmap[j].red   = tcmap[j].red;
  1715.         xa_cmap[j].green = tcmap[j].green;
  1716.         xa_cmap[j].blue  = tcmap[j].blue;
  1717.         xa_cmap[j].gray  = tcmap[j].gray;
  1718.       }
  1719.  
  1720. /* POD TEMP share routine whith CHDR install */
  1721.   if (x11_cmap_flag == TRUE)
  1722.   {
  1723.     DEBUG_LEVEL2 fprintf(stderr,"CMAP: size=%ld off=%ld\n",
  1724.                 xa_cmap_size,xa_cmap_off);
  1725.     if (x11_display_type & XA_X11_GRAY)
  1726.     {
  1727.       for(j=0;j<xa_cmap_size;j++)
  1728.       {
  1729.         defs[j].pixel = xa_cmap_off + j;
  1730.         defs[j].red   = xa_cmap[j].gray;
  1731.         defs[j].green = xa_cmap[j].gray;
  1732.         defs[j].blue  = xa_cmap[j].gray;
  1733.         defs[j].flags = DoRed | DoGreen | DoBlue;
  1734.       }
  1735.     }
  1736.     else
  1737.     {
  1738.       for(j=0; j<xa_cmap_size;j++)
  1739.       {
  1740.         defs[j].pixel = xa_cmap_off + j;
  1741.         defs[j].red   = xa_cmap[j].red;
  1742.         defs[j].green = xa_cmap[j].green;
  1743.         defs[j].blue  = xa_cmap[j].blue;
  1744.         defs[j].flags = DoRed | DoGreen | DoBlue;
  1745.         DEBUG_LEVEL3 fprintf(stderr," %ld) %lx %lx %lx <%ld>\n",
  1746.           j,xa_cmap[j].red,xa_cmap[j].green,xa_cmap[j].blue,xa_cmap[j].gray);
  1747.  
  1748.       }
  1749.     }
  1750.     XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  1751.     XSync(theDisp,False);
  1752.   }
  1753.  
  1754.     
  1755.     }
  1756.     break;
  1757.        /* 
  1758.         * Lower Color Intensity by 1/16.
  1759.         */
  1760.      case ACT_FADE:     
  1761.                         {
  1762.                          LONG j;
  1763.  
  1764.                          DEBUG_LEVEL2 fprintf(stderr,"ACT_FADE:\n");
  1765.                          if ( (x11_display_type & XA_X11_CMAP) &&
  1766.                               (x11_cmap_flag    == TRUE) )
  1767.                          {
  1768.                            for(j=0;j<xa_cmap_size;j++)
  1769.                            {
  1770.                              if (xa_cmap[j].red   <= 16) xa_cmap[j].red   = 0;
  1771.                              else xa_cmap[j].red   -= 16;
  1772.                              if (xa_cmap[j].green <= 16) xa_cmap[j].green = 0;
  1773.                              else xa_cmap[j].green -= 16;
  1774.                              if (xa_cmap[j].blue  <= 16) xa_cmap[j].blue  = 0;
  1775.                              else xa_cmap[j].blue  -= 16;
  1776.  
  1777.                              defs[j].pixel = j;
  1778.                              defs[j].red   = xa_cmap[j].red   << 8;
  1779.                              defs[j].green = xa_cmap[j].green << 8;
  1780.                              defs[j].blue  = xa_cmap[j].blue  << 8;
  1781.                              defs[j].flags = DoRed | DoGreen | DoBlue;
  1782.                            }
  1783.                            XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  1784.                            XFlush(theDisp);
  1785.                          }
  1786.                         }
  1787.                         break;
  1788.        /* 
  1789.         * A IMAGE display only part of an IMAGE.
  1790.         */
  1791.      case ACT_IMAGE:   
  1792.     {
  1793.       Pixmap pix_map = 0;
  1794.       ACT_IMAGE_HDR *act_im_hdr;
  1795.  
  1796.       DEBUG_LEVEL2 fprintf(stderr,"ACT_IMAGE:\n");
  1797.       act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
  1798.       DEBUG_LEVEL2 fprintf(stderr,"  <%ld,%ld> <%ld,%ld>\n",
  1799.         act_im_hdr->xpos,  act_im_hdr->ypos,
  1800.                 act_im_hdr->xsize, act_im_hdr->ysize  );
  1801.  
  1802.       if (xa_need_to_scale_b)
  1803.       {
  1804.         UBYTE *tmp_pic;
  1805.         ULONG xp,yp,xsize,ysize;
  1806.  
  1807.         if(act_im_hdr->clip)
  1808.         {
  1809.           xsize = act_im_hdr->xsize; ysize = act_im_hdr->ysize;
  1810.           xp = act_im_hdr->xpos; yp = act_im_hdr->ypos;
  1811.           tmp_pic = UTIL_Scale_Bitmap(0,act_im_hdr->clip,
  1812.         act_im_hdr->xsize,act_im_hdr->ysize,
  1813.         (X11_Get_Bitmap_Width(xsize)/8),xa_buff_x,xa_buff_y,
  1814.         xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1815.         X11_LSB,X11_LSB);
  1816.           if (tmp_pic)
  1817.           {
  1818.                 pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  1819.               (char *)tmp_pic,
  1820.               X11_Get_Bitmap_Width(xsize),ysize,0x01,0x00,1);
  1821.                 XSetClipMask(theDisp,theGC,pix_map);
  1822.                 XSetClipOrigin(theDisp,theGC,xp,yp);
  1823.           }
  1824.           else pix_map = 0;
  1825.         }
  1826.  
  1827.         xp = act_im_hdr->xpos; yp = act_im_hdr->ypos;
  1828.         if (x11_display_type == XA_MONOCHROME)
  1829.           tmp_pic = UTIL_Scale_Bitmap(0,act_im_hdr->image->data,
  1830.         act_im_hdr->xsize,act_im_hdr->ysize,
  1831.         act_im_hdr->image->bytes_per_line,xa_buff_x,xa_buff_y,
  1832.         xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1833.         x11_bit_order,x11_bit_order);
  1834.         else
  1835.           tmp_pic = UTIL_Scale_Mapped(0,act_im_hdr->image->data,
  1836.            0,0, act_im_hdr->xsize, act_im_hdr->ysize,
  1837.            act_im_hdr->image->bytes_per_line,
  1838.            xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  1839.            x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  1840.         if (tmp_pic)
  1841.         {
  1842.           theImage->data = (char *)tmp_pic;
  1843.         
  1844.           DEBUG_LEVEL1 fprintf(stderr,"IMAGE:scale sz %ldx%ld -> %ldx%ld\n",
  1845.         act_im_hdr->xsize,act_im_hdr->ysize,xsize,ysize);
  1846.           DEBUG_LEVEL1 fprintf(stderr,"IMAGE:scale ps %ldx%ld -> %ldx%ld\n",
  1847.         act_im_hdr->xpos,act_im_hdr->ypos,xp,yp);
  1848.               X11_Init_Image_Struct(theImage,xsize,ysize);
  1849.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1850.         XA_Install_CMAP(act->chdr);
  1851.           XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  1852.         }
  1853.         if(act_im_hdr->clip) XSetClipMask(theDisp,theGC,None);
  1854.       }
  1855.       else /* Not scaling Image */
  1856.       {
  1857.             if(act_im_hdr->clip)
  1858.             {
  1859.               pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  1860.                 (char *)act_im_hdr->clip,
  1861.                 X11_Get_Bitmap_Width(act_im_hdr->xsize),act_im_hdr->ysize,
  1862.                 0x01,0x00,1);
  1863.               XSetClipMask(theDisp,theGC,pix_map);
  1864.               XSetClipOrigin(theDisp,theGC,act_im_hdr->xpos,act_im_hdr->ypos);
  1865.             }
  1866.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1867.         XA_Install_CMAP(act->chdr);
  1868.         XPutImage(theDisp,mainW,theGC,act_im_hdr->image, 0, 0,
  1869.         act_im_hdr->xpos,  act_im_hdr->ypos,
  1870.         act_im_hdr->xsize, act_im_hdr->ysize  );
  1871.             if (act_im_hdr->clip)
  1872.         {
  1873.           XSetClipMask(theDisp,theGC,None);
  1874.               XFreePixmap(theDisp,pix_map);
  1875.         }
  1876.       }
  1877.           XSync(theDisp,False);
  1878.           if (xa_pixmap_flag == TRUE) XA_Image_To_Pixmap(act);
  1879.     }
  1880.     break;
  1881.  
  1882.        /* 
  1883.         * A PIXMAP 
  1884.         */
  1885.      case ACT_PIXMAP:   
  1886.     {
  1887.       ACT_PIXMAP_HDR *act_pm_hdr;
  1888.  
  1889.       DEBUG_LEVEL2 fprintf(stderr,"ACT_PIXMAP:\n");
  1890.       act_pm_hdr = (ACT_PIXMAP_HDR *)(act->data);
  1891.  
  1892.           if (xa_need_to_scale_b)
  1893.           {
  1894.         Pixmap pix_map;
  1895.         XImage *t_image,*p_image;
  1896.         UBYTE *tmp_pic;
  1897.             ULONG xp,yp,xsize,ysize;
  1898.  
  1899.         if (act_pm_hdr->clip)
  1900.         {
  1901.           xp = act_pm_hdr->xpos;      yp = act_pm_hdr->ypos;
  1902.           xsize = act_pm_hdr->xsize;  ysize = act_pm_hdr->ysize;
  1903.               p_image = XGetImage(theDisp,act_pm_hdr->clip,0,0,xsize,ysize,
  1904.                 1,XYPixmap);
  1905.               tmp_pic = UTIL_Scale_Bitmap(0,p_image->data,
  1906.                 xsize,ysize,p_image->bytes_per_line,xa_buff_x,xa_buff_y,
  1907.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1908.                     x11_bit_order,X11_LSB);
  1909.               if (tmp_pic)
  1910.           {
  1911.                 pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  1912.                 (char *)tmp_pic, X11_Get_Bitmap_Width(xsize),
  1913.                 ysize,0x01,0x00,1);
  1914.                 XSetClipMask(theDisp,theGC,pix_map);
  1915.                 XSetClipOrigin(theDisp,theGC,xp,yp);
  1916.           } else pix_map = 0;
  1917.         }
  1918.  
  1919.         xp = act_pm_hdr->xpos;    yp = act_pm_hdr->ypos;
  1920.         xsize = act_pm_hdr->xsize;    ysize = act_pm_hdr->ysize;
  1921.             t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  1922.                 AllPlanes,ZPixmap);
  1923.         if (x11_display_type == XA_MONOCHROME)
  1924.         {
  1925.               t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  1926.                 1,XYPixmap);
  1927.               tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  1928.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  1929.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1930.                     x11_bit_order,x11_bit_order);
  1931.         }
  1932.         else
  1933.         {
  1934.               t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  1935.                 AllPlanes,ZPixmap);
  1936.               tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  1937.                    0,0, xsize, ysize, t_image->bytes_per_line,
  1938.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  1939.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  1940.         }
  1941.         if (tmp_pic) /* if image to draw */
  1942.         {
  1943.           theImage->data = (char *)tmp_pic;
  1944.           X11_Init_Image_Struct(theImage,xsize,ysize);
  1945.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1946.           XA_Install_CMAP(act->chdr);
  1947.               XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  1948.             }
  1949.         if (act_pm_hdr->clip) 
  1950.         {
  1951.           XSetClipMask(theDisp,theGC,None);
  1952.           XDestroyImage(p_image);
  1953.               if (pix_map) XFreePixmap(theDisp,pix_map);
  1954.         }
  1955.         XDestroyImage(t_image);
  1956.         XSync(theDisp,False);
  1957.           }
  1958.           else /* no rescale */
  1959.           {
  1960.         if (act_pm_hdr->clip)
  1961.         {
  1962.               XSetClipMask(theDisp,theGC,act_pm_hdr->clip);
  1963.               XSetClipOrigin(theDisp,theGC,act_pm_hdr->xpos,act_pm_hdr->ypos);
  1964.           XSetPlaneMask(theDisp,theGC,AllPlanes);
  1965.         }
  1966.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1967.         XA_Install_CMAP(act->chdr);
  1968.         XCopyArea(theDisp,act_pm_hdr->pixmap,mainW,theGC, 0, 0, 
  1969.         act_pm_hdr->xsize, act_pm_hdr->ysize,
  1970.         act_pm_hdr->xpos,  act_pm_hdr->ypos   );
  1971.         XSync(theDisp,False);
  1972.         if (act_pm_hdr->clip) XSetClipMask(theDisp,theGC,None);
  1973.           }
  1974.     }
  1975.     break;
  1976.  
  1977.        /* 
  1978.         * SETTERS 
  1979.         */
  1980.      case ACT_IMAGES:
  1981.     {
  1982.       ACT_SETTER_HDR *act_ims_hdr;
  1983.       ACT_PIXMAP_HDR *work_pm_hdr;
  1984.       Pixmap work;
  1985.       ACT_IMAGE_HDR *back_im_hdr;
  1986.       XImage *back;
  1987.       LONG xpback,ypback;
  1988.  
  1989.       DEBUG_LEVEL2 fprintf(stderr,"ACT_SETTERS: im\n");
  1990.       act_ims_hdr = (ACT_SETTER_HDR *)(act->data);
  1991.  
  1992.       /* work still needs to be PIXMAP */
  1993.           if (act_ims_hdr->work->type != ACT_PIXMAP)
  1994.         XA_Image_To_Pixmap(act_ims_hdr->work);
  1995.       work_pm_hdr = (ACT_PIXMAP_HDR *)act_ims_hdr->work->data;
  1996.       work = work_pm_hdr->pixmap;
  1997.  
  1998.       back_im_hdr = (ACT_IMAGE_HDR *)act_ims_hdr->back->data;
  1999.       back = back_im_hdr->image;
  2000.  
  2001.       /* copy backgrnd into work area */
  2002.       DEBUG_LEVEL2 
  2003.         fprintf(stderr,"ACT_SETTERS: back=%lx work=%lx\n",(ULONG)back,work);
  2004.       xpback = act_ims_hdr->xpback;
  2005.       ypback = act_ims_hdr->ypback;
  2006.       DEBUG_LEVEL2 
  2007.         fprintf(stderr,"             bpos = <%ld,%ld>\n",xpback,ypback);
  2008.       {
  2009.         LONG xback,yback;
  2010.         LONG xlen,ylen,xlen1,ylen1;
  2011.  
  2012.         xback = act_ims_hdr->xback;
  2013.         yback = act_ims_hdr->yback;
  2014.         xlen = xback - xpback;
  2015.         ylen = yback - ypback;
  2016.         if (xlen >= xa_buff_x) xlen1 = 0;
  2017.         else xlen1 = xa_buff_x - xlen;
  2018.         if (ylen >= xa_buff_y) ylen1 = 0;
  2019.         else ylen1 = xa_buff_y - ylen;
  2020.  
  2021.         if (xlen1 == 0)
  2022.         { 
  2023.           if (ylen1 == 0)
  2024.           {
  2025.          XPutImage(theDisp, work, theGC, back,
  2026.               xpback,ypback,0,0,xa_buff_x,xa_buff_y );
  2027.           }
  2028.           else
  2029.           {
  2030.          XPutImage(theDisp, work, theGC, back,
  2031.               xpback,ypback,0,   0, xa_buff_x,ylen);
  2032.          XPutImage(theDisp, work, theGC, back,
  2033.               xpback,    0, 0,ylen, xa_buff_x,ylen1);
  2034.           }
  2035.         }
  2036.         else /* xlen1 != 0 */
  2037.         { 
  2038.           if (ylen1 == 0)
  2039.           {
  2040.          XPutImage(theDisp, work, theGC, back,
  2041.               xpback,ypback,0,   0,xlen ,xa_buff_y);
  2042.          XPutImage(theDisp, work, theGC, back,
  2043.                   0,ypback,xlen, 0,xlen1,xa_buff_y);
  2044.           }
  2045.           else
  2046.           {
  2047.          XPutImage(theDisp, work, theGC, back,
  2048.               xpback,ypback,    0,    0,  xlen,  ylen);
  2049.          XPutImage(theDisp, work, theGC, back,
  2050.                   0,    0, xlen, ylen, xlen1, ylen1);
  2051.          XPutImage(theDisp, work, theGC, back,
  2052.                   0,ypback, xlen,    0, xlen1,  ylen);
  2053.          XPutImage(theDisp, work, theGC, back,
  2054.               xpback,    0,    0, ylen,  xlen, ylen1);
  2055.           }
  2056.         }
  2057.       }
  2058.  
  2059.       /* loop through face pixmaps */
  2060.       while(act_ims_hdr != 0)
  2061.       {
  2062.         ACT_IMAGE_HDR *face_im_hdr;
  2063.         Pixmap pix_map = 0;
  2064.  
  2065.         face_im_hdr = (ACT_IMAGE_HDR *)act_ims_hdr->face->data;
  2066.         if (face_im_hdr->clip)
  2067.         {
  2068.               pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  2069.                 (char *)face_im_hdr->clip,
  2070.                 X11_Get_Bitmap_Width(face_im_hdr->xsize),face_im_hdr->ysize,
  2071.                 0x01,0x00,1);
  2072.               XSetClipMask(theDisp,theGC,pix_map);
  2073.               XSetClipOrigin(theDisp,theGC,
  2074.         act_ims_hdr->xpface,act_ims_hdr->ypface);
  2075.             }
  2076.         XPutImage(theDisp, work, theGC,face_im_hdr->image,
  2077.           0, 0, act_ims_hdr->xpface,  act_ims_hdr->ypface,
  2078.                 act_ims_hdr->xface, act_ims_hdr->yface    );
  2079.  
  2080.             if(face_im_hdr->clip)
  2081.             {
  2082.               XSetClipMask(theDisp,theGC,None);
  2083.               XFreePixmap(theDisp,pix_map);
  2084.             }
  2085.         act_ims_hdr = act_ims_hdr->next;
  2086.       }
  2087.  
  2088.       if (xa_need_to_scale_b)
  2089.       {
  2090.         XImage *t_image;
  2091.         ULONG xp,yp,xsize,ysize;
  2092.         UBYTE *tmp_pic;
  2093.         xp = yp = 0; xsize = xa_buff_x; ysize = xa_buff_y;
  2094.         if (x11_display_type == XA_MONOCHROME)
  2095.         {
  2096.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,1,XYPixmap);
  2097.               tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  2098.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  2099.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  2100.                     x11_bit_order,x11_bit_order);
  2101.         }
  2102.         else
  2103.         {
  2104.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,AllPlanes,ZPixmap);
  2105.               tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  2106.                    0,0, xsize, ysize, t_image->bytes_per_line,
  2107.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  2108.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  2109.         }
  2110.             if (tmp_pic)
  2111.         {
  2112.               theImage->data = (char *)tmp_pic;
  2113.               X11_Init_Image_Struct(theImage,xsize,ysize);
  2114.               if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2115.                   XA_Install_CMAP(act->chdr);
  2116.               XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  2117.         }
  2118.             XDestroyImage(t_image);
  2119.       }
  2120.       else /* not scaling */
  2121.       {
  2122.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2123.         XA_Install_CMAP(act->chdr);
  2124.         XCopyArea(theDisp,work,mainW,theGC,0,0,xa_disp_x,xa_disp_y,0, 0);
  2125.       }
  2126.       XSync(theDisp,False);
  2127.     }
  2128.     break;
  2129.  
  2130.        /* 
  2131.         * SETTERS 
  2132.         */
  2133.      case ACT_PIXMAPS:
  2134.     {
  2135.       ACT_SETTER_HDR *act_pms_hdr;
  2136.       ACT_PIXMAP_HDR *back_pm_hdr,*work_pm_hdr;
  2137.       Pixmap work,back;
  2138.       LONG xpback,ypback;
  2139.  
  2140.       DEBUG_LEVEL2 fprintf(stderr,"ACT_SETTERS:\n");
  2141.       act_pms_hdr = (ACT_SETTER_HDR *)(act->data);
  2142.  
  2143.           if (act_pms_hdr->back->type != ACT_PIXMAP)
  2144.         XA_Image_To_Pixmap(act_pms_hdr->back);
  2145.           if (act_pms_hdr->work->type != ACT_PIXMAP)
  2146.         XA_Image_To_Pixmap(act_pms_hdr->work);
  2147.       back_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->back->data;
  2148.       work_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->work->data;
  2149.       back = back_pm_hdr->pixmap;
  2150.       work = work_pm_hdr->pixmap;
  2151.  
  2152.       /* copy backgrnd into work area */
  2153.       DEBUG_LEVEL2 
  2154.         fprintf(stderr,"ACT_SETTERS: back=%lx work=%lx\n",back,work);
  2155.       xpback = act_pms_hdr->xpback;
  2156.       ypback = act_pms_hdr->ypback;
  2157.       DEBUG_LEVEL2 
  2158.         fprintf(stderr,"             bpos = <%ld,%ld>\n",xpback,ypback);
  2159.       {
  2160.         LONG xback,yback;
  2161.         LONG xlen,ylen,xlen1,ylen1;
  2162.  
  2163.         xback = act_pms_hdr->xback;
  2164.         yback = act_pms_hdr->yback;
  2165.         xlen = xback - xpback;
  2166.         ylen = yback - ypback;
  2167.         if (xlen >= xa_buff_x) xlen1 = 0;
  2168.         else xlen1 = xa_buff_x - xlen;
  2169.         if (ylen >= xa_buff_y) ylen1 = 0;
  2170.         else ylen1 = xa_buff_y - ylen;
  2171.  
  2172.         if (xlen1 == 0)
  2173.         { 
  2174.           if (ylen1 == 0)
  2175.           {
  2176.              XCopyArea(theDisp, back, work, theGC,
  2177.               xpback,ypback,xa_buff_x,xa_buff_y,0,0);
  2178.           }
  2179.           else
  2180.           {
  2181.              XCopyArea(theDisp, back, work, theGC,
  2182.               xpback,ypback,xa_buff_x,ylen ,0,   0);
  2183.              XCopyArea(theDisp, back, work, theGC,
  2184.               xpback,    0,xa_buff_x,ylen1,0,ylen);
  2185.           }
  2186.         }
  2187.         else /* xlen1 != 0 */
  2188.         { 
  2189.           if (ylen1 == 0)
  2190.           {
  2191.              XCopyArea(theDisp, back, work, theGC,
  2192.               xpback,ypback,xlen ,xa_buff_y,0,   0);
  2193.              XCopyArea(theDisp, back, work, theGC,
  2194.                   0,ypback,xlen1,xa_buff_y,xlen,0);
  2195.           }
  2196.           else
  2197.           {
  2198.              XCopyArea(theDisp, back, work, theGC,
  2199.               xpback,ypback,  xlen,  ylen,    0,    0);
  2200.              XCopyArea(theDisp, back, work, theGC,
  2201.                   0,    0, xlen1, ylen1, xlen, ylen);
  2202.              XCopyArea(theDisp, back, work, theGC,
  2203.                   0,ypback, xlen1,  ylen, xlen,    0);
  2204.              XCopyArea(theDisp, back, work, theGC,
  2205.               xpback,    0,  xlen, ylen1,    0, ylen);
  2206.           }
  2207.         }
  2208.       }
  2209.  
  2210.       /* loop through face pixmaps */
  2211.       while(act_pms_hdr != 0)
  2212.       {
  2213.         ULONG ret;
  2214.         ACT_PIXMAP_HDR *face_pm_hdr;
  2215.  
  2216.             if (act_pms_hdr->face->type != ACT_PIXMAP)
  2217.                 ret = XA_Image_To_Pixmap(act_pms_hdr->face);
  2218.         face_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->face->data;
  2219.         if (face_pm_hdr->clip)
  2220.         {
  2221.               XSetClipMask(theDisp,theGC,face_pm_hdr->clip);
  2222.               XSetClipOrigin(theDisp,theGC,
  2223.         act_pms_hdr->xpface,act_pms_hdr->ypface);
  2224.         }
  2225.  
  2226.         XCopyArea(theDisp,
  2227.           face_pm_hdr->pixmap, work, theGC,
  2228.           0, 0, 
  2229.           act_pms_hdr->xface, act_pms_hdr->yface,
  2230.           act_pms_hdr->xpface,  act_pms_hdr->ypface   );
  2231.         if (face_pm_hdr->clip) XSetClipMask(theDisp,theGC,None);
  2232.         act_pms_hdr = act_pms_hdr->next;
  2233.       }
  2234.  
  2235.       if (xa_need_to_scale_b)
  2236.       {
  2237.         XImage *t_image;
  2238.         ULONG xp,yp,xsize,ysize;
  2239.         UBYTE *tmp_pic;
  2240.         xp = yp = 0; xsize = xa_buff_x; ysize = xa_buff_y;
  2241.         if (x11_display_type == XA_MONOCHROME)
  2242.         {
  2243.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,1,XYPixmap);
  2244.               tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  2245.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  2246.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  2247.                     x11_bit_order,x11_bit_order);
  2248.         }
  2249.         else
  2250.         {
  2251.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,AllPlanes,ZPixmap);
  2252.               tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  2253.                    0,0, xsize, ysize, t_image->bytes_per_line,
  2254.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  2255.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  2256.         }
  2257.             if (tmp_pic)
  2258.         {
  2259.               theImage->data = (char *)tmp_pic;
  2260.               X11_Init_Image_Struct(theImage,xsize,ysize);
  2261.               if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2262.                   XA_Install_CMAP(act->chdr);
  2263.               XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  2264.         }
  2265.             XDestroyImage(t_image);
  2266.       }
  2267.       else
  2268.       {
  2269.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2270.         XA_Install_CMAP(act->chdr);
  2271.         XCopyArea(theDisp,work,mainW,theGC,0,0,xa_disp_x,xa_disp_y,0, 0);
  2272.       }
  2273.       XSync(theDisp,False);
  2274.     }
  2275.     break;
  2276.  
  2277.        /* 
  2278.         * Act upon IFF Color Cycling chunk.
  2279.         */
  2280.      case ACT_CYCLE:
  2281. {
  2282. /* if there is a new_chdr, install it, not the old one */
  2283. /*
  2284.  XA_CHDR *the_chdr;
  2285. if (act->chdr->new_chdr) the_chdr = act->chdr->new_chdr;
  2286. else the_chdr = act->chdr;
  2287. */
  2288.  
  2289.         if (   (cmap_play_nice == FALSE) 
  2290.         && (x11_display_type & XA_X11_CMAP)
  2291.         && (xa_anim_flags & ANIM_CYCLE) )
  2292.     {
  2293.       ACT_CYCLE_HDR *act_cycle;
  2294.       act_cycle = (ACT_CYCLE_HDR *)act->data;
  2295.  
  2296.       DEBUG_LEVEL2 fprintf(stderr,"ACT_CYCLE:\n");
  2297.       if ( !(act_cycle->flags & ACT_CYCLE_STARTED) )
  2298.       {
  2299.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2300.             XA_Install_CMAP(act->chdr);
  2301.           xa_cycle_cnt++;
  2302.           act_cycle->flags |= ACT_CYCLE_STARTED;
  2303.           xa_now_cycling = TRUE;
  2304.           XtAppAddTimeOut(theContext,(int)(act_cycle->rate), 
  2305.           (XtTimerCallbackProc)XA_Cycle_It, (XtPointer)(act_cycle));
  2306.       }
  2307.     }
  2308. } /*POD*/
  2309.     break;
  2310.  
  2311.      case ACT_DELTA:        
  2312.      {
  2313.     ACT_DLTA_HDR *dlta_hdr = (ACT_DLTA_HDR *)act->data;
  2314.     ULONG xsrc,ysrc,xdst,ydst,xsize,ysize,*remap_map;
  2315.     ULONG xbuff,ybuff,map_flag,dith_flag,dlta_flag;
  2316.     XA_CHDR *the_chdr;
  2317.     char *the_pic;
  2318.     ULONG no_shared;
  2319.  
  2320.         no_shared = 0;
  2321.     if (cmap_dither_type == CMAP_DITHER_FLOYD) dith_flag = TRUE;
  2322.     else dith_flag = FALSE; 
  2323.     /* if there is a new_chdr, install it, not the old one */
  2324.     if (act->chdr->new_chdr) 
  2325.     {
  2326.       /* if dithering and new_chdr then don't remap while decoding */
  2327.       if (dith_flag)  map_flag = FALSE;
  2328.       else map_flag = TRUE;
  2329.       the_chdr = act->chdr->new_chdr;
  2330.     }
  2331.     else 
  2332.     {
  2333.       /* remap to larger pixel size NOTE: all anim are 1 byte */
  2334.       if (   (x11_display_type & XA_X11_TRUE)
  2335.           || (x11_kludge_1 == TRUE)
  2336.           || (x11_bytes_pixel != 1)          ) map_flag = TRUE;
  2337.       else map_flag = FALSE;
  2338.       dith_flag = FALSE;
  2339.       the_chdr = act->chdr;
  2340.     }
  2341.     remap_map = act->chdr->map;
  2342.  
  2343.     the_pic = xa_pic; xbuff = xa_imagex; ybuff = xa_imagey;
  2344.     if ((xa_fd >= 0) && (!(dlta_hdr->flags & DLTA_DATA)) )
  2345.     {
  2346.       XA_Read_Delta(xa_codec_buf,xa_fd,dlta_hdr->fpos,dlta_hdr->fsize);
  2347.       dlta_flag = dlta_hdr->delta(the_pic,xa_codec_buf,dlta_hdr->fsize,
  2348.             act->chdr,remap_map,map_flag,xbuff,ybuff,xa_imaged,
  2349.             &xsrc,&ysrc,&xsize,&ysize,dlta_hdr->special,
  2350.             dlta_hdr->extra);
  2351.     }
  2352.     else
  2353.     {
  2354.       dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,dlta_hdr->fsize,
  2355.             act->chdr,remap_map,map_flag,xbuff,ybuff,xa_imaged,
  2356.             &xsrc,&ysrc,&xsize,&ysize,dlta_hdr->special,
  2357.             dlta_hdr->extra);
  2358.     }
  2359.     if (x11_expose_flag == TRUE) { x11_expose_flag = FALSE;
  2360.         xsrc = ysrc = 0; xsize = xbuff; ysize = ybuff; }
  2361.     else if (dlta_flag & ACT_DLTA_NOP) { act->type = ACT_NOP; break; }
  2362.  
  2363.     if (dlta_flag & ACT_DLTA_BODY)
  2364.     {
  2365.       if (im_buff0 && (im_buff0 != the_pic) )
  2366.         memcpy((char *)im_buff0, (char *)the_pic, xa_image_size);
  2367.       if (im_buff1 && (im_buff1 != the_pic) )
  2368.         memcpy((char *)im_buff1, (char *)the_pic, xa_image_size);
  2369.       xsize = dlta_hdr->xsize; ysize = dlta_hdr->ysize;
  2370.       xa_image_size = xa_imagex * xa_imagey;
  2371.       IFF_Init_DLTA_HDR(xsize,ysize);
  2372.     }
  2373.     if (xa_anim_flags & ANIM_DBL_BUF)
  2374.     {
  2375.       IFF_Update_DLTA_HDR(&xsrc,&ysrc,&xsize,&ysize);
  2376.       xa_pic = (xa_pic==im_buff0)?im_buff1:im_buff0;
  2377.     } 
  2378.  
  2379.     /* convert min/max to pos/size */
  2380.     xsize -= xsrc;    ysize -= ysrc;
  2381.     xdst = xsrc; ydst = ysrc;
  2382.         if (xsize == 0) {act->type = ACT_NOP; fprintf(stderr,"QQ\n"); break;}
  2383.  
  2384.         if (xa_anim_flags & ANIM_HAM)
  2385.     {
  2386.       xsize =  4*((xsize+3)/4); /* PODTEST */
  2387.       if (xa_anim_flags & ANIM_HAM6) IFF_Buffer_HAM6(im_buff2,the_pic,
  2388.         act->chdr,act->h_cmap,xsize,ysize,xsrc,ysrc,xbuff,TRUE);
  2389.       else             IFF_Buffer_HAM8(im_buff2,the_pic,
  2390.         act->chdr,act->h_cmap,xsize,ysize,xsrc,ysrc,xbuff,TRUE);
  2391.       the_pic = im_buff2;
  2392. #ifdef XSHM
  2393.           if (shm) { sh_Image = im2_Image; }
  2394. #endif
  2395.       dlta_flag |= ACT_DLTA_MAPD;
  2396.       xsrc = ysrc = 0; xbuff = xsize; ybuff = ysize;
  2397.     }
  2398.  
  2399.     if (x11_display_type == XA_MONOCHROME)
  2400.     { no_shared = 1;
  2401.       if (xa_need_to_scale_u)
  2402.       {
  2403.         UBYTE *tmp_pic;
  2404.         ULONG line_size;
  2405.         tmp_pic = UTIL_Scale_Mapped(0,the_pic,0,0,
  2406.             xbuff,ybuff, xbuff,
  2407.             xa_imagex,xa_imagey, xa_disp_x,xa_disp_y,
  2408.             x11_bytes_pixel,&xdst,&ydst,&xsize,&ysize,0);
  2409.         if (tmp_pic == 0) break; /* NOP */
  2410.         line_size = X11_Get_Line_Size(xsize);
  2411.         UTIL_Mapped_To_Bitmap(tmp_pic,tmp_pic,act->chdr,0,0,
  2412.             xsize,ysize,xsize,ysize,line_size);
  2413.         xsrc = ysrc = 0;
  2414.             theImage->data = (char *)tmp_pic;
  2415.             X11_Init_Image_Struct(theImage,xsize,ysize);
  2416.       } /* end of scale */
  2417.       else
  2418.       {
  2419.         ULONG line_size,tsize;
  2420.         tsize = ysize * X11_Get_Line_Size(xsize);
  2421.         XA_REALLOC(xa_disp_buff,xa_disp_buff_size,tsize);
  2422.         line_size = X11_Get_Line_Size(xbuff);
  2423.         UTIL_Mapped_To_Bitmap(xa_disp_buff,the_pic,act->chdr,
  2424.             xsrc,ysrc,xsize,ysize,xbuff,ybuff,line_size);
  2425.         xsrc = ysrc = 0;
  2426.             theImage->data = xa_disp_buff;
  2427.             X11_Init_Image_Struct(theImage,xsize,ysize);
  2428.       }
  2429.     } /* end of mono */
  2430.         else
  2431.         {
  2432.       if (dith_flag == TRUE) /* map here if dithering is on */
  2433.       {
  2434.         if (cmap_dither_type == CMAP_DITHER_FLOYD)
  2435.         {
  2436.           UTIL_Mapped_To_Floyd(im_buff2,the_pic,
  2437.                   act->chdr->new_chdr,act->chdr,xsrc,ysrc,
  2438.             xsize,ysize,xbuff,ybuff);
  2439.         xsrc = ysrc = 0; xbuff = xsize; ybuff = ysize;
  2440.         the_pic = im_buff2;    dlta_flag |= ACT_DLTA_MAPD;
  2441. #ifdef XSHM
  2442.         if (shm) 
  2443.         { sh_Image = im2_Image; 
  2444.               X11_Init_Image_Struct(im2_Image,xbuff,ybuff);
  2445.         }
  2446. #endif
  2447.         }
  2448.       } /* end of dither */
  2449.  
  2450.       if (xa_need_to_scale_u)
  2451.       {
  2452.         XA_CHDR *tmp_chdr;
  2453.         UBYTE *tmp_pic;
  2454.         no_shared = 1;
  2455.         if ((map_flag==TRUE) && (!(dlta_flag & ACT_DLTA_MAPD)) )
  2456.                 tmp_chdr = the_chdr;
  2457.         else tmp_chdr = 0;
  2458.         tmp_pic = UTIL_Scale_Mapped(0,the_pic,xsrc,ysrc,
  2459.               xsize,ysize,X11_Get_Line_Size(xbuff),
  2460.               xa_imagex,xa_imagey,xa_disp_x,xa_disp_y,
  2461.               x11_bytes_pixel,&xdst,&ydst,&xsize,&ysize,tmp_chdr);
  2462.             if (tmp_pic==0) break; /*NOP*/
  2463.             xsrc = ysrc = 0;
  2464.         theImage->data = (char *)tmp_pic;
  2465.         xbuff = xsize; ybuff = ysize;
  2466.       } /* end of scaling */
  2467.       else /* no scaling */
  2468.       {
  2469.         if (   ((x11_bytes_pixel > 1) && (!(dlta_flag & ACT_DLTA_MAPD)))
  2470.             || ((map_flag==TRUE) && (!(dlta_flag & ACT_DLTA_MAPD)))     )
  2471.         {
  2472.         ULONG tsize = (xsize) * (ysize) * x11_bytes_pixel;
  2473.         XA_REALLOC(xa_disp_buff,xa_disp_buff_size,tsize);
  2474.         UTIL_Mapped_To_Mapped(xa_disp_buff,the_pic,act->chdr,
  2475.             xsrc,ysrc,xsize,ysize,xbuff,ybuff);
  2476.         xsrc = ysrc = 0;
  2477.         theImage->data = (char *)xa_disp_buff;
  2478.         xbuff = xsize; ybuff = ysize;
  2479.             no_shared = 1;
  2480.         } 
  2481.         else 
  2482.         { 
  2483. #ifdef XSHM
  2484.           if (shm) sh_Image->data = the_pic;
  2485. #endif
  2486.           theImage->data = the_pic;
  2487.         }
  2488.       } /* end of no scaling */
  2489.  
  2490.           if (x11_pack_flag == TRUE)
  2491.       { no_shared = 1;
  2492.         UTIL_Pack_Image(im_buff3,theImage->data,xbuff,ybuff);
  2493.         theImage->data = im_buff3;
  2494.       }
  2495. #ifdef XSHM
  2496.       if (sh_Image) X11_Init_Image_Struct(sh_Image,xbuff,ybuff);
  2497. #endif
  2498.       X11_Init_Image_Struct(theImage,xbuff,ybuff);
  2499.         } /* end of not mono */
  2500.  
  2501.     if (xa_no_disp == FALSE)
  2502.     {
  2503.       if ( (the_chdr != 0) && (the_chdr != xa_chdr_now) )
  2504.                         XA_Install_CMAP(the_chdr);
  2505. #ifdef XSHM
  2506.     if (shm && (no_shared==0) )
  2507.     {
  2508. DEBUG_LEVEL1  fprintf(stderr,"sh_IMAGE = %lx sh_image->data = %lx \n",sh_Image,sh_Image->data);
  2509. DEBUG_LEVEL1  fprintf(stderr,"     from <%ld,%ld> to <%ld,%ld> <%ld,%ld>\n",xsrc,ysrc,xdst,ydst,xsize,ysize);
  2510.             XSync(theDisp, False);
  2511.         XShmPutImage(theDisp,mainW,theGC,sh_Image,
  2512.                 xsrc,ysrc,xdst,ydst,xsize,ysize,True );
  2513.     } else
  2514. #endif
  2515.           {
  2516.         XPutImage(theDisp,mainW,theGC,theImage,
  2517.                 xsrc,ysrc,xdst,ydst,xsize,ysize );
  2518.           }
  2519.       XSync(theDisp,False);
  2520.     }
  2521. #ifdef XSHM
  2522.     if ( (shm) && (xa_anim_flags & ANIM_DBL_BUF) ) 
  2523.           {sh_Image = (xa_pic==im_buff0)?im0_Image:im1_Image;}
  2524.         /* note: xa_pic already swapped */
  2525. #endif
  2526.       } /* end of DELTA case */
  2527.       break;
  2528.  
  2529.      default:           
  2530.                         fprintf(stderr,"Unknown not supported %lx\n",act->type);
  2531.     } /* end of switch of action type */
  2532.  } /* end of action valid */
  2533.  
  2534.  if (xa_pause_hdr)
  2535.  {
  2536.    if (cur_frame==xa_pause_hdr->frame)
  2537.    {
  2538.      xa_pause_hdr = xa_pause_hdr->next;
  2539.      goto XA_PAUSE_ENTRY_POINT;
  2540.    }
  2541.  }
  2542.  
  2543.  
  2544.  if (xa_anim_status & XA_STEP_MASK) /* Single step if in that mode */
  2545.  {
  2546.    XA_PAUSE_ENTRY_POINT:
  2547.    if ( (xa_no_disp == FALSE) & (xa_title_flag != XA_TITLE_NONE) )
  2548.    {
  2549.      sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  2550.      XStoreName(theDisp,mainW,xa_title);
  2551.    }
  2552.    xa_anim_status &= XA_CLEAR_MASK; /* preserve direction and stop */
  2553.    xa_anim_status |= XA_STOP_MASK;
  2554.    xa_anim_holdoff = FALSE;
  2555.    return;
  2556.  }
  2557.  
  2558.  if ( (xa_no_disp == FALSE) & (xa_title_flag == XA_TITLE_FRAME) )
  2559.  {
  2560.    sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  2561.    XStoreName(theDisp,mainW,xa_title);
  2562.  }
  2563.   /* Harry, what time is it? and how much left? default to 1 ms */
  2564.  t_frame_end = XA_Time_Read() - t_frame_start;
  2565.  t_frame_end = t_frame_int - t_frame_end;
  2566.  if (t_frame_end <=0 ) t_frame_end = 1; 
  2567.  t_frame_end = (xa_speed_scale * t_frame_end) >> 16; 
  2568.  if (t_frame_end <=0 ) t_frame_end = 1;
  2569.  /* if ran out of time, jump back real quick */
  2570. /* was just benchmarking
  2571.  if ( (t_frame_end <= 0) && !(xa_anim_status & XA_STOP_MASK) )
  2572.  {
  2573.    command == XA_SHOW_NORM;
  2574.    goto ShowAction_Loop;
  2575.  }
  2576. */
  2577.  
  2578.  if ( !(xa_anim_status & XA_STOP_MASK) )
  2579.    XtAppAddTimeOut(theContext,t_frame_end,(XtTimerCallbackProc)ShowAction,
  2580.                         (XtPointer)(XA_SHOW_NORM));
  2581.  else xa_anim_holdoff = FALSE;
  2582. }
  2583. #endif
  2584.  
  2585. /*
  2586.  *
  2587.  */
  2588. void Step_Action_Next()
  2589. {
  2590.   XA_FRAME *frame;
  2591.  
  2592.   cur_frame++; frame = &cur_file->frame_lst[cur_frame];
  2593.   do
  2594.   { ULONG jmp2end_flag = 0;
  2595.     if ( (frame->time == 0) && (frame->act != 0) ) /* check for loops */
  2596.     {
  2597.       XA_ACTION *lp_act = frame->act;
  2598.       if (lp_act->type == ACT_BEG_LP)
  2599.       {
  2600.         ACT_BEG_LP_HDR *beg_lp = (ACT_BEG_LP_HDR *)lp_act->data;
  2601.         beg_lp->cnt_var = beg_lp->count;
  2602.         cur_frame++; /* move on */
  2603.       }
  2604.       else if (lp_act->type == ACT_END_LP)
  2605.       {
  2606.         ACT_END_LP_HDR *end_lp = (ACT_END_LP_HDR *)lp_act->data;
  2607.         *end_lp->cnt_var = *end_lp->cnt_var - 1;
  2608.         if (*end_lp->cnt_var > 0) cur_frame = end_lp->begin_frame;
  2609.         else cur_frame++;
  2610.       }
  2611.       else if (lp_act->type == ACT_JMP2END)
  2612.       { 
  2613.     if (xa_pingpong_flag==FALSE)
  2614.     {
  2615.       if (   ((cur_floop+1) >= cur_file->loop_num)
  2616.               && (first_file->next_file != first_file)
  2617.          )
  2618.         cur_frame = cur_file->last_frame + 1; /* jmp to end */
  2619.       else    cur_frame++;
  2620.         } else jmp2end_flag = 1;
  2621.       }
  2622.       frame = &cur_file->frame_lst[cur_frame];
  2623.     }
  2624.  
  2625.     if ( (frame->act == 0) /* Are we at the end of an anim? */
  2626.         || (jmp2end_flag) )
  2627.     {
  2628.       if (xa_pingpong_flag == TRUE)
  2629.       { jmp2end_flag = 0;
  2630.         xa_anim_status &= ~(XA_NEXT_MASK);  /* change dir to prev */
  2631.         cur_frame--; 
  2632.         Step_Action_Prev();
  2633.         return;
  2634.       }
  2635.       cur_frame = cur_file->loop_frame;
  2636.  
  2637.       cur_floop++;
  2638.       DEBUG_LEVEL1 fprintf(stderr,"  loop = %ld\n",cur_floop);
  2639.  
  2640.       /* Done looping animation. Move on to next file if present */
  2641.       if (   (cur_floop >= cur_file->loop_num)
  2642.       || (xa_anim_status & XA_STEP_MASK)   ) /* or if single stepping */
  2643.       {
  2644.         cur_floop = 0;             /* Reset Loop Count */
  2645.  
  2646.     /* Are we on the last file and do we need to exit? */
  2647.     if (   (cur_file->next_file == first_file)
  2648.         && (xa_exit_flag == TRUE) )   TheEnd(); /* later */
  2649.  
  2650.         /* This is a special case check.
  2651.          * If more that one file, reset file_is_started, otherwise
  2652.          * if we're only displaying 1 animation jump to the loop_frame
  2653.          * which has already been set up above.
  2654.          */
  2655.         if (first_file->next_file != first_file)
  2656.         {
  2657.           file_is_started = FALSE;
  2658.           cur_file = cur_file->next_file;
  2659.           cur_frame = 0;
  2660.         }
  2661.         DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2662.         if (xa_time_flag == TRUE) XA_Time_Check();
  2663.       } /* end done looping file */
  2664.     } /* end done with frames in file */
  2665.     frame = &cur_file->frame_lst[cur_frame];
  2666.   } while( (frame->time == 0) || (frame->act == 0) );
  2667. }
  2668.  
  2669. /*
  2670.  *
  2671.  */
  2672. void Step_Action_Prev()
  2673. {
  2674.   XA_FRAME *frame;
  2675.   cur_frame--; if (cur_frame < 0) goto XA_Step_Action_Prev_0;
  2676.   frame = &cur_file->frame_lst[cur_frame];
  2677.  
  2678.   do
  2679.   {
  2680.     if ( (frame->time == 0) && (frame->act != 0) ) /* check for loops */
  2681.     {
  2682.       XA_ACTION *lp_act = frame->act;
  2683.       if (lp_act->type == ACT_BEG_LP)
  2684.       {
  2685.         ACT_BEG_LP_HDR *beg_lp = (ACT_BEG_LP_HDR *)lp_act->data;
  2686.         beg_lp->cnt_var++;
  2687.         if (beg_lp->cnt_var < beg_lp->count) cur_frame = beg_lp->end_frame;
  2688.         else cur_frame--;
  2689.       }
  2690.       else if (lp_act->type == ACT_END_LP)
  2691.       {
  2692.         ACT_END_LP_HDR *end_lp = (ACT_END_LP_HDR *)lp_act->data;
  2693.         *end_lp->cnt_var = 0;
  2694.         cur_frame--;
  2695.       }
  2696.       else if (lp_act->type == ACT_JMP2END)
  2697.       { /* not valid in this direction so just skip over it */
  2698.         cur_frame--;
  2699.       }
  2700.       if (cur_frame < 0) goto XA_Step_Action_Prev_0;
  2701.       frame = &cur_file->frame_lst[cur_frame];
  2702.     }
  2703.  
  2704.     /* Are we at the beginning of an anim? */
  2705.     if (cur_frame < 0) goto XA_Step_Action_Prev_0;
  2706.     if (   (frame->act == 0) || (cur_frame < cur_file->loop_frame)
  2707.        )
  2708.     {
  2709.       XA_Step_Action_Prev_0:  /* skip indexing with -1 */
  2710.  
  2711.       if (xa_pingpong_flag == TRUE)
  2712.       {
  2713.         xa_anim_status |= XA_NEXT_MASK;  /* change dir to forward */
  2714.         cur_floop++;
  2715.  
  2716.     /* Are we on the last file and do we need to exit? */
  2717.     if (   (cur_file->next_file == first_file)
  2718.         && (xa_exit_flag == TRUE) )   TheEnd(); /* later */
  2719.  
  2720.          /* do we move to next file? */
  2721.         if (  (first_file->next_file != first_file)  /* more than 1 file */
  2722.         && (   (cur_floop >= cur_file->loop_num)
  2723.                 || (xa_anim_status & XA_STEP_MASK)  ) )
  2724.         {
  2725.           cur_floop = 0;
  2726.           file_is_started = FALSE;
  2727.           cur_file = cur_file->next_file;
  2728.           cur_frame = 0;
  2729.           break;
  2730.         }
  2731.  
  2732.         if (cur_floop >= cur_file->loop_num) 
  2733.         {
  2734.           cur_floop = 0;
  2735.           if (xa_time_flag == TRUE) XA_Time_Check();
  2736.         }
  2737.         cur_frame++;
  2738.         Step_Action_Next();
  2739.         return;
  2740.       } /* end of pingpong stuff */
  2741.  
  2742.       cur_frame = cur_file->last_frame;
  2743.       cur_floop--;
  2744.       DEBUG_LEVEL1 fprintf(stderr,"  loop = %ld\n",cur_floop);
  2745.        /* Done looping animation. Move on to next file if present */
  2746.       if (   (cur_floop <= 0)
  2747.       || (xa_anim_status & XA_STEP_MASK) ) /* or if single stepping */
  2748.       {
  2749.         cur_floop = cur_file->loop_num; /* Reset Loop Count */
  2750.  
  2751.         /* If more that one file, go to next file */
  2752.         if (first_file->next_file != first_file )
  2753.         {
  2754.           file_is_started = FALSE;
  2755.           cur_file = cur_file->prev_file;
  2756.           cur_frame = cur_file->last_frame;
  2757.           cur_floop = cur_file->loop_num; /* Reset Loop Count */
  2758.         }
  2759.  
  2760.         if (xa_time_flag == TRUE) XA_Time_Check();
  2761.         DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2762.       } /* end done looping file */
  2763.     } /* end done with frames in file */
  2764.     frame = &cur_file->frame_lst[cur_frame];
  2765.   } while( (frame->time == 0) || (frame->act == 0) );
  2766. }
  2767.  
  2768.  
  2769. /*
  2770.  *
  2771.  */
  2772. void Step_Frame_Next()
  2773. {
  2774.   cur_frame++;
  2775.   do
  2776.   {
  2777.       /* skip over loops */
  2778.     if (   (cur_file->frame_lst[cur_frame].time == 0)
  2779.         && (cur_file->frame_lst[cur_frame].act != 0) ) cur_frame++;
  2780.  
  2781.       /* Are we at the end of an anim? */
  2782.     if (cur_file->frame_lst[cur_frame].act == 0)
  2783.     {
  2784.       cur_frame = cur_file->loop_frame;
  2785.     }
  2786.   } while(   (cur_file->frame_lst[cur_frame].time == 0)
  2787.           || (cur_file->frame_lst[cur_frame].act == 0)  );
  2788. }
  2789.  
  2790. /*
  2791.  *
  2792.  */
  2793. void Step_Frame_Prev()
  2794. {
  2795.   cur_frame--;
  2796.  
  2797.   do
  2798.   {
  2799.       /* skip over loops */
  2800.     if (cur_frame < 0) goto XA_Step_Frame_Prev_0;
  2801.     if (   (cur_file->frame_lst[cur_frame].time == 0)
  2802.         && (cur_file->frame_lst[cur_frame].act != 0) ) cur_frame--;
  2803.  
  2804.     /* Are we at the beginning of an anim? */
  2805.     if (cur_frame < 0) goto XA_Step_Frame_Prev_0;
  2806.     if (   (cur_file->frame_lst[cur_frame].act == 0)
  2807.         || (cur_frame < cur_file->loop_frame)        )
  2808.     {
  2809.       XA_Step_Frame_Prev_0: /* prevent indexing with -1 */
  2810.       cur_frame = cur_file->last_frame;
  2811.     }
  2812.   } while(   (cur_file->frame_lst[cur_frame].time == 0)
  2813.           || (cur_file->frame_lst[cur_frame].act == 0)  );
  2814. }
  2815.  
  2816. /*
  2817.  *
  2818.  */
  2819. void Step_File_Next()
  2820. {
  2821.   file_is_started = FALSE;
  2822.   cur_frame = 0;
  2823.   cur_file = cur_file->next_file;
  2824.   cur_floop = 0; /* used if things start up again */
  2825.  
  2826.   DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2827. }
  2828.  
  2829. /*
  2830.  *
  2831.  */
  2832. void Step_File_Prev()
  2833. {
  2834.   file_is_started = FALSE;
  2835.   cur_frame = 0;
  2836.   cur_file = cur_file->prev_file;
  2837.   cur_floop = 0; /* used if things start up again */
  2838.  
  2839.   DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2840. }
  2841.  
  2842.  
  2843. /*
  2844.  * Simple routine to find out the file type. Defaults to FLI.
  2845.  */
  2846. LONG Determine_Anim_Type(filename)
  2847. char *filename;
  2848. { LONG ret;
  2849.  if ( Is_RLE_File(filename)==TRUE)    return(RLE_ANIM);
  2850. #if SETFILE
  2851.  if ( Is_SET_File(filename)==TRUE)    return(SET_ANIM);
  2852. #endif
  2853.  if ( Is_IFF_File(filename)==TRUE)    return(IFF_ANIM); 
  2854.  if ( Is_GIF_File(filename)==TRUE)    return(GIF_ANIM); 
  2855.  if ( Is_TXT_File(filename)==TRUE)    return(TXT_ANIM); 
  2856.  if ( Is_FLI_File(filename)==TRUE)    return(FLI_ANIM); 
  2857.  if ( Is_PFX_File(filename)==TRUE)    return(PFX_ANIM);
  2858.  if ( Is_AVI_File(filename)==TRUE)    return(AVI_ANIM); 
  2859.  if ( (ret=Is_QT_File(filename))==TRUE) return(QT_ANIM);
  2860.  if (ret == XA_NOFILE)            return(NOFILE_ANIM);
  2861.  if ( Is_DL_File(filename)==TRUE)    return(DL_ANIM);
  2862.  return(UNKNOWN_ANIM);
  2863. }
  2864.  
  2865.  #if XWIN
  2866. /*
  2867.  *
  2868.  */
  2869. void XA_Cycle_Wait(nothing, id)
  2870. char *nothing;
  2871. XtIntervalId *id;
  2872. {
  2873.  
  2874.   if (xa_cycle_cnt) /* wait until cycles are done */
  2875.   {
  2876.     XtAppAddTimeOut(theContext, 50, (XtTimerCallbackProc)XA_Cycle_Wait,
  2877.                             (XtPointer)(NULL));
  2878.     return;
  2879.   }
  2880.   else /* then move on */
  2881.   {
  2882.     xa_now_cycling = FALSE;
  2883.     XtAppAddTimeOut(theContext, 1, (XtTimerCallbackProc)ShowAction, 
  2884.                         (XtPointer)(XA_SHOW_SKIP));
  2885.   }
  2886. }
  2887.  
  2888. /*
  2889.  *
  2890.  */
  2891. void XA_Cycle_It(act_cycle, id)
  2892. ACT_CYCLE_HDR   *act_cycle;
  2893. XtIntervalId *id;
  2894. {
  2895.   ULONG i,*i_ptr,size,curpos;
  2896.  
  2897.   if (xa_anim_flags & ANIM_CYCLE) XtAppAddTimeOut(theContext,
  2898.         (int)(act_cycle->rate),(XtTimerCallbackProc)XA_Cycle_It,
  2899.                         (XtPointer)(act_cycle));
  2900.   else
  2901.   {
  2902.     xa_cycle_cnt--;
  2903.     act_cycle->flags &= ~ACT_CYCLE_STARTED;
  2904.     return;
  2905.   }
  2906.  
  2907.   size = act_cycle->size;
  2908.   curpos = act_cycle->curpos;
  2909.  
  2910.   /* increment or decrement curpos */
  2911.   if (act_cycle->flags & ACT_CYCLE_REVERSE) 
  2912.       curpos = (curpos)?(curpos - 1):(size - 1); 
  2913.   else
  2914.       curpos = (curpos >= (size - 1))?(0):(curpos + 1); 
  2915.   act_cycle->curpos = curpos;
  2916.  
  2917.   i_ptr = (ULONG *)act_cycle->data;
  2918.   for(i=0;i<size;i++)
  2919.   {
  2920.     ULONG j;
  2921.  
  2922.     j = i_ptr[i] - xa_cmap_off;
  2923.     defs[i].pixel = i_ptr[curpos];
  2924.     defs[i].flags = DoRed | DoGreen | DoBlue;
  2925.     if (x11_display_type & XA_X11_GRAY)
  2926.     {
  2927.       defs[i].red = defs[i].green = defs[i].blue = xa_cmap[j].gray;
  2928.     }
  2929.     else
  2930.     {
  2931.       defs[i].red   = xa_cmap[j].red;
  2932.       defs[i].green = xa_cmap[j].green;
  2933.       defs[i].blue  = xa_cmap[j].blue;
  2934.     }
  2935.     if (act_cycle->flags & ACT_CYCLE_REVERSE) 
  2936.       curpos = (curpos)?(curpos - 1):(size - 1); 
  2937.     else
  2938.       curpos = (curpos >= (size - 1))?(0):(curpos + 1); 
  2939.   }
  2940.   XStoreColors(theDisp,theCmap,defs,act_cycle->size);
  2941.   XSync(theDisp,False);
  2942. }
  2943. #endif
  2944.  
  2945. /*
  2946.  *
  2947.  */
  2948. void Free_Actions(acts)
  2949. XA_ACTION *acts;
  2950. {
  2951.   XA_ACTION *act;
  2952.   act = acts;
  2953.   while(act != 0)
  2954.   {
  2955.     ACT_Free_Act(act);
  2956.     act = act->next;
  2957.   }
  2958. }
  2959.  
  2960. XA_ANIM_HDR *Return_Anim_Hdr(file_hdr)
  2961. XA_ANIM_HDR *file_hdr;
  2962. {
  2963.   XA_ANIM_HDR *tmp_hdr;
  2964.   if ((file_hdr==0) || (first_file==0)) TheEnd1("Return_Anim_Hdr err");
  2965.   xa_file_num--;
  2966.   if (first_file == file_hdr)
  2967.   {
  2968.     first_file = 0;
  2969.     tmp_hdr = 0;
  2970.   }
  2971.   else /* removed file_hdr from the loop */
  2972.   {
  2973.     tmp_hdr = file_hdr->prev_file;
  2974.     tmp_hdr->next_file = file_hdr->next_file;
  2975.     file_hdr->next_file->prev_file = tmp_hdr;
  2976.   }
  2977.   FREE(file_hdr,0x01);
  2978.   return(tmp_hdr);
  2979. }
  2980.  
  2981. XA_ANIM_HDR *Get_Anim_Hdr(file_hdr,file_name)
  2982. XA_ANIM_HDR *file_hdr;
  2983. char *file_name;
  2984. {
  2985.   XA_ANIM_HDR *temp_hdr;
  2986.   LONG length;
  2987.  
  2988.   temp_hdr = (XA_ANIM_HDR *)malloc( sizeof(XA_ANIM_HDR) );
  2989.   if (temp_hdr == 0) TheEnd1("Get_Anim_Hdr: malloc failed\n");
  2990.  
  2991.   if (first_file == 0) first_file = temp_hdr;
  2992.   if (file_hdr == 0)
  2993.   {
  2994.     xa_file_num = 0;
  2995.     temp_hdr->next_file = temp_hdr;
  2996.     temp_hdr->prev_file = temp_hdr;
  2997.   }
  2998.   else
  2999.   {
  3000.     temp_hdr->prev_file = file_hdr;
  3001.     temp_hdr->next_file = file_hdr->next_file;
  3002.     file_hdr->next_file = temp_hdr;
  3003.     first_file->prev_file = temp_hdr;
  3004.   }
  3005.  
  3006.   temp_hdr->anim_type = 0;
  3007.   temp_hdr->imagex = 0;
  3008.   temp_hdr->imagey = 0;
  3009.   temp_hdr->imagec = 0;
  3010.   temp_hdr->imaged = 0;
  3011.   temp_hdr->anim_flags    = 0;
  3012.   temp_hdr->loop_num    = 0;
  3013.   temp_hdr->loop_frame    = 0;
  3014.   temp_hdr->last_frame    = 0;
  3015.   temp_hdr->frame_lst    = 0;
  3016.   temp_hdr->acts    = 0;
  3017.   temp_hdr->file_num    = xa_file_num;
  3018.   temp_hdr->fname    = 0;
  3019.   temp_hdr->max_fsize    = 0;
  3020.   xa_file_num++;
  3021.  
  3022.   length = strlen(file_name);
  3023.   temp_hdr->name = (char *)malloc(length + 1);
  3024.   strcpy(temp_hdr->name,file_name);
  3025.   return(temp_hdr);
  3026. }
  3027.   
  3028. #if XWIN
  3029. void XA_Install_CMAP(chdr)
  3030. XA_CHDR *chdr;
  3031. { ColorReg *tcmap;
  3032.   LONG j;
  3033.  
  3034.   tcmap        = chdr->cmap;
  3035.   xa_cmap_size    = chdr->csize;
  3036.   if (xa_cmap_size > x11_cmap_size) xa_cmap_size = x11_cmap_size;
  3037.   xa_cmap_off    = chdr->coff;
  3038.   xa_map    = chdr->map;
  3039.   xa_map_size    = chdr->msize;
  3040.   xa_map_off    = chdr->moff;
  3041.   for(j=0; j<xa_cmap_size;j++)
  3042.   {
  3043.     xa_cmap[j].red   = tcmap[j].red;
  3044.     xa_cmap[j].green = tcmap[j].green;
  3045.     xa_cmap[j].blue  = tcmap[j].blue;
  3046.     xa_cmap[j].gray  = tcmap[j].gray;
  3047.   }
  3048.  
  3049.   DEBUG_LEVEL1 fprintf(stderr,"  Install CMAP %lx old was %lx\n",
  3050.                     (ULONG)chdr,(ULONG)xa_chdr_now);
  3051.  
  3052.   if ( x11_cmap_flag == FALSE )
  3053.   {
  3054.     DEBUG_LEVEL1 fprintf(stderr,"  Fake Install since cmap not writable\n");
  3055.     xa_chdr_now = chdr;
  3056.     return;
  3057.   }
  3058.   else /* install the cmap */
  3059.   {
  3060.     DEBUG_LEVEL2 fprintf(stderr,"CMAP: size=%ld off=%ld\n",
  3061.         xa_cmap_size,xa_cmap_off);
  3062.     if (xa_cmap_size > x11_cmap_size)
  3063.     {
  3064.       fprintf(stderr,"Install CMAP: Error csize(%ld) > x11 cmap(%ld)\n",
  3065.         xa_cmap_size,x11_cmap_size);
  3066.       return;
  3067.     }
  3068.     if (x11_display_type & XA_X11_GRAY)
  3069.     {
  3070.       for(j=0;j<xa_cmap_size;j++)
  3071.       {
  3072.         defs[j].pixel = xa_cmap_off + j;
  3073.         defs[j].red   = xa_cmap[j].gray;
  3074.         defs[j].green = xa_cmap[j].gray;
  3075.         defs[j].blue  = xa_cmap[j].gray;
  3076.         defs[j].flags = DoRed | DoGreen | DoBlue;
  3077.         DEBUG_LEVEL3 fprintf(stderr," g %ld) %lx %lx %lx <%lx>\n",
  3078.              j,xa_cmap[j].red,xa_cmap[j].green,xa_cmap[j].blue,xa_cmap[j].gray);
  3079.         
  3080.       }
  3081.     }
  3082.     else
  3083.     {
  3084.       for(j=0; j<xa_cmap_size;j++)
  3085.       {
  3086.         defs[j].pixel = xa_cmap_off + j;
  3087.         defs[j].red   = xa_cmap[j].red;
  3088.         defs[j].green = xa_cmap[j].green;
  3089.         defs[j].blue  = xa_cmap[j].blue;
  3090.         defs[j].flags = DoRed | DoGreen | DoBlue;
  3091.         DEBUG_LEVEL3 fprintf(stderr," %ld) %lx %lx %lx <%lx>\n",
  3092.              j,xa_cmap[j].red,xa_cmap[j].green,xa_cmap[j].blue,xa_cmap[j].gray);
  3093.         
  3094.       }
  3095.     }
  3096.     XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  3097.     /* XSync(theDisp,False); */
  3098.     /* following is a kludge to force the cmap to be loaded each time 
  3099.      * this sometimes helps synchronize image to vertical refresh on
  3100.      * machines that wait until vertical refresh to load colormap
  3101.      */
  3102.     if (cmap_force_load == FALSE) xa_chdr_now = chdr;
  3103.   }
  3104. }
  3105. #endif
  3106.  
  3107. void XA_Time_Init()
  3108. {
  3109.   gettimeofday(&tv, 0);
  3110.   xa_time_off = tv.tv_sec;
  3111. }
  3112.  
  3113. /*
  3114.  * return time from start in milliseconds
  3115.  */
  3116. LONG XA_Time_Read()
  3117. {
  3118.   LONG t;
  3119.   gettimeofday(&tv, 0);
  3120.   t = (tv.tv_sec - xa_time_off) * 1000 + (tv.tv_usec / 1000);
  3121.   return(t);
  3122. }
  3123.  
  3124.  
  3125. /*
  3126.  *
  3127.  */
  3128. void XA_Time_Check()
  3129. {
  3130.   LONG time_int;
  3131.  
  3132.   xa_time_end = XA_Time_Read();
  3133.   time_int = xa_time_end - xa_time_start;
  3134.   xa_time_av = (xa_time_av * xa_time_num) + time_int;
  3135.   xa_time_num++;
  3136.   xa_time_av /= xa_time_num;
  3137.   fprintf(stderr,"l_time = %ld  av %ld\n",time_int,xa_time_av);
  3138.   xa_time_start = XA_Time_Read();
  3139.  
  3140. }
  3141.  
  3142. #if XWIN
  3143. ULONG
  3144. XA_Image_To_Pixmap(act)
  3145. XA_ACTION *act;
  3146. {
  3147.   ACT_IMAGE_HDR *act_im_hdr;
  3148.   ACT_PIXMAP_HDR *act_pm_hdr;
  3149.   ULONG line_size;
  3150.  
  3151.   if (act->type == ACT_NOP) return(0);
  3152.   if (act->type != ACT_IMAGE) 
  3153.   { 
  3154.     fprintf(stderr,"XA_Image_To_Pixmap: not Image err %lx\n",act->type);
  3155.     TheEnd();
  3156.   }
  3157.   act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
  3158.   act_pm_hdr = (ACT_PIXMAP_HDR *) malloc( sizeof(ACT_PIXMAP_HDR) );
  3159.   if (act_pm_hdr == 0) TheEnd1("Image_to_Pixmap: malloc err\n");
  3160.  
  3161.   if (x11_display_type == XA_MONOCHROME)
  3162.     line_size = X11_Get_Bitmap_Width(act_im_hdr->xsize);
  3163.   else line_size = act_im_hdr->xsize;
  3164.  
  3165.   if(act_im_hdr->clip)
  3166.   {
  3167.     act_pm_hdr->clip = 
  3168.     XCreatePixmapFromBitmapData(theDisp,mainW,
  3169.                 (char *)act_im_hdr->clip,
  3170.                 X11_Get_Bitmap_Width(act_im_hdr->xsize),act_im_hdr->ysize,
  3171.                 0x01,0x00,1);
  3172.     XSync(theDisp,False);
  3173.   }
  3174.   else act_pm_hdr->clip = 0;
  3175.  
  3176.   act->type = ACT_PIXMAP;
  3177.   act->data = (UBYTE *) act_pm_hdr;
  3178.   act_pm_hdr->xpos  = act_im_hdr->xpos;
  3179.   act_pm_hdr->ypos  = act_im_hdr->ypos;
  3180.   act_pm_hdr->xsize = act_im_hdr->xsize;
  3181.   act_pm_hdr->ysize = act_im_hdr->ysize;
  3182.   act_pm_hdr->pixmap = XCreatePixmap(theDisp,mainW,
  3183.                 line_size, act_pm_hdr->ysize, x11_depth);
  3184.   XSync(theDisp,False);
  3185.   DEBUG_LEVEL2 fprintf(stderr,
  3186.     "XA_Image_To_Pixmap: pixmap = %lx\n", act_pm_hdr->pixmap);
  3187.   XSetClipMask(theDisp,theGC,None);
  3188.   XPutImage(theDisp, act_pm_hdr->pixmap, theGC, act_im_hdr->image,
  3189.       0,0,0,0,act_pm_hdr->xsize,act_pm_hdr->ysize);
  3190.   XSync(theDisp,False);
  3191.   if (act_im_hdr->clip) { FREE(act_im_hdr->clip,0x01); act_im_hdr->clip=0;}
  3192.   XDestroyImage(act_im_hdr->image);
  3193.   FREE(act_im_hdr,0x01);
  3194.   return(1);
  3195. }
  3196. #endif
  3197.  
  3198. ULONG XA_Read_Int(s,j)
  3199. UBYTE *s;
  3200. ULONG *j;
  3201. {
  3202.   ULONG i,num;
  3203.   i = *j; num = 0;
  3204.   while( (s[i] >= '0') && (s[i] <= '9') )
  3205.     { num *= 10; num += (ULONG)(s[i]) - (ULONG)('0'); i++; }
  3206.   *j = i;   
  3207.   return(num);
  3208. }
  3209.  
  3210. float XA_Read_Float(s,j)
  3211. UBYTE *s;
  3212. ULONG *j;
  3213. {
  3214.   ULONG i;
  3215.   float num;
  3216.   i = *j; num = 0.0;
  3217.   while( (s[i] >= '0') && (s[i] <= '9') )
  3218.     { num *= 10; num += (float)(s[i]) - (float)('0'); i++; }
  3219.   if (s[i] == '.')
  3220.   {
  3221.     float pos = 10.0;
  3222.     i++; 
  3223.     while( (s[i] >= '0') && (s[i] <= '9') )
  3224.     { 
  3225.       num += ((float)(s[i]) - (float)('0')) / pos;
  3226.       pos *= 10.0; i++;
  3227.     }
  3228.   }
  3229.   *j = i;   
  3230.   return(num);
  3231. }
  3232.  
  3233. LONG XA_Get_Class(p)
  3234. char *p;
  3235. {
  3236.   ULONG i,len;
  3237.   char tmp[16];
  3238.   
  3239.   /* copy and convert to lower case */
  3240.   len = strlen(p); if (len > 16) return( -1 );
  3241.   for(i=0; i < len; i++) tmp[i] = (char)tolower( (int)(p[i]) );
  3242.   tmp[i] = 0;
  3243.   if      (strcmp(tmp,"staticgray\0" ) == 0)    return( StaticGray );
  3244.   else if (strcmp(tmp,"grayscale\0"  ) == 0)    return( GrayScale );
  3245.   else if (strcmp(tmp,"staticcolor\0") == 0)    return( StaticColor );
  3246.   else if (strcmp(tmp,"pseudocolor\0") == 0)    return( PseudoColor );
  3247.   else if (strcmp(tmp,"truecolor\0"  ) == 0)    return( TrueColor );
  3248.   else if (strcmp(tmp,"directcolor\0") == 0)    return( DirectColor );
  3249.   else return( -1 );
  3250. }
  3251.  
  3252. void XA_Read_Delta(dptr,fd,fpos,fsize)
  3253. char *dptr;
  3254. int fd;
  3255. ULONG fpos,fsize;
  3256. {
  3257.   LONG ret;
  3258.   ret = lseek(fd,fpos,SEEK_SET);
  3259.   if (ret != fpos) TheEnd1("XA_Read_Delta: Can't seek fpos");
  3260.   ret = read(fd,dptr,fsize);
  3261.   if (ret != fsize) TheEnd1("XA_Read_Delta: Can't read data");
  3262. }
  3263.  
  3264. /**********************
  3265.  * Add frame to current pause list
  3266.  */
  3267. void XA_Add_Pause(frame)
  3268. ULONG frame;            /* frame at which to pause */
  3269. { XA_PAUSE *new_phdr;
  3270.  
  3271.   new_phdr = (XA_PAUSE *)malloc(sizeof(XA_PAUSE));
  3272.   if (new_phdr==0) TheEnd1("XA_Add_Pause: malloc err\n");
  3273.   new_phdr->frame = frame;
  3274.   new_phdr->next = 0;
  3275.   if (xa_pause_hdr==0) xa_pause_hdr = new_phdr;
  3276.   else
  3277.   { XA_PAUSE *t_phdr = xa_pause_hdr;
  3278.     while(t_phdr->next != 0) t_phdr = t_phdr->next;
  3279.     t_phdr->next = new_phdr;
  3280.   }
  3281. }
  3282.  
  3283. /* NEW CODE GOES HERE */
  3284.  
  3285.  
  3286. /***********************************************************************
  3287.  *
  3288.  *
  3289.  ***************/
  3290. void Hard_Death()
  3291. {
  3292.   XA_ANIM_HDR *tmp_hdr;
  3293.   if (xa_fd >= 0) { close(xa_fd); xa_fd = -1; }
  3294.   if (xa_codec_buf) { FREE(xa_codec_buf,0x99); xa_codec_buf=0;}
  3295.   if (cur_file !=0 )
  3296.   {
  3297.     cur_file = first_file;
  3298.     first_file->prev_file->next_file = 0;  /* last file's next ptr to 0 */
  3299.   }
  3300.   while( cur_file != 0)
  3301.   {
  3302.     Free_Actions(cur_file->acts);
  3303.     tmp_hdr = cur_file->next_file;
  3304.     if (cur_file->name) FREE(cur_file->name,0x01);
  3305.     FREE(cur_file,0x01);
  3306.     cur_file = tmp_hdr;
  3307.   }
  3308.   if (!shm)
  3309.   {
  3310.     if (im_buff0) { FREE(im_buff0,0x01); im_buff0=0; }
  3311.     if (im_buff1) { FREE(im_buff1,0x01); im_buff1=0; }
  3312.     if (im_buff2) { FREE(im_buff2,0x01); im_buff2=0; }
  3313.   }
  3314.   if (im_buff3) { FREE(im_buff3,0x01); im_buff3=0; }
  3315.   if (xa_disp_buff) { FREE(xa_disp_buff,0x01); xa_disp_buff=0; }
  3316.   if (xa_scale_buff) { FREE(xa_scale_buff,0x01); xa_scale_buff=0; }
  3317.   if (xa_scale_row_buff) { FREE(xa_scale_row_buff,0x01); xa_scale_row_buff=0;}
  3318.   if (xa_cmap) { FREE(xa_cmap,0x01); xa_cmap=0; }
  3319.   if (xa_ham_map) { FREE(xa_ham_map,0x001); xa_ham_map=0;}
  3320.   while(xa_chdr_start)
  3321.   {
  3322.     XA_CHDR *tmp;
  3323.     tmp = xa_chdr_start;
  3324.     xa_chdr_start = xa_chdr_start->next;
  3325.     if (tmp->cmap) { FREE(tmp->cmap,0x01); tmp->cmap=0; }
  3326.     if (tmp->map) { FREE(tmp->map,0x01); tmp->map=0; }
  3327.     FREE(tmp,0x01);
  3328.   }
  3329. #ifdef XSHM
  3330.   if (shm)
  3331.   {
  3332.     if (im0_shminfo.shmaddr) { XShmDetach(theDisp,&im0_shminfo);
  3333.              shmdt(im0_shminfo.shmaddr); }
  3334.     if (im1_shminfo.shmaddr) { XShmDetach(theDisp,&im1_shminfo);
  3335.              shmdt(im1_shminfo.shmaddr); }
  3336.     if (im2_shminfo.shmaddr) { XShmDetach(theDisp,&im2_shminfo);
  3337.              shmdt(im2_shminfo.shmaddr); }
  3338.     if (im0_Image)
  3339.     {
  3340.       im0_Image->data = 0;
  3341.       XDestroyImage(im0_Image);
  3342.     }
  3343.     if (im1_Image)
  3344.     {
  3345.       im1_Image->data = 0;
  3346.       XDestroyImage(im1_Image);
  3347.     }
  3348.     if (im2_Image)
  3349.     {
  3350.       im2_Image->data = 0;
  3351.       XDestroyImage(im2_Image);
  3352.     }
  3353.   }
  3354. #endif
  3355.   exit(0);
  3356. }
  3357.  
  3358. /*
  3359.  * This function (hopefully) provides a clean exit from our code.
  3360.  */
  3361. void TheEnd()
  3362. {
  3363.   XA_ANIM_HDR *tmp_hdr;
  3364.  
  3365.   if (xa_fd>=0) { close(xa_fd); xa_fd = -1; }
  3366.   if (xa_codec_buf) { FREE(xa_codec_buf,0x99); xa_codec_buf=0;}
  3367.   if (cur_file !=0 )
  3368.   {
  3369.     cur_file = first_file;
  3370.     first_file->prev_file->next_file = 0;  /* last file's next ptr to 0 */
  3371.   }
  3372.   while( cur_file != 0)
  3373.   {
  3374.     Free_Actions(cur_file->acts);
  3375.     tmp_hdr = cur_file->next_file;
  3376.     if (cur_file->name) { FREE(cur_file->name,0x01); cur_file->name = 0; }
  3377.     FREE(cur_file,0x01);
  3378.     cur_file = tmp_hdr;
  3379.   }
  3380.   if (!shm)
  3381.   {
  3382.     if (im_buff0) { FREE(im_buff0,0x01); im_buff0=0; }
  3383.     if (im_buff1) { FREE(im_buff1,0x01); im_buff1=0; }
  3384.     if (im_buff2) { FREE(im_buff2,0x01); im_buff2=0; }
  3385.   }
  3386.   if (im_buff3) { FREE(im_buff3,0x01); im_buff3=0; }
  3387.   if (xa_disp_buff) { FREE(xa_disp_buff,0x01); xa_disp_buff=0; }
  3388.   if (xa_scale_buff) { FREE(xa_scale_buff,0x01); xa_scale_buff=0; }
  3389.   if (xa_scale_row_buff) { FREE(xa_scale_row_buff,0x01); xa_scale_row_buff=0;}
  3390.   if (xa_cmap) { FREE(xa_cmap,0x01); xa_cmap=0; }
  3391.   if (xa_ham_map) { FREE(xa_ham_map,0x001); xa_ham_map=0;}
  3392. #ifdef XSHM
  3393.   if (shm)
  3394.   {
  3395.     if (im0_shminfo.shmaddr) { XShmDetach(theDisp,&im0_shminfo);
  3396.              shmdt(im0_shminfo.shmaddr); }
  3397.     if (im1_shminfo.shmaddr) { XShmDetach(theDisp,&im1_shminfo);
  3398.              shmdt(im1_shminfo.shmaddr); }
  3399.     if (im2_shminfo.shmaddr) { XShmDetach(theDisp,&im2_shminfo);
  3400.              shmdt(im2_shminfo.shmaddr); }
  3401.     if (im0_Image)
  3402.     {
  3403.       im0_Image->data = 0;
  3404.       XDestroyImage(im0_Image);
  3405.     }
  3406.     if (im1_Image)
  3407.     {
  3408.       im1_Image->data = 0;
  3409.       XDestroyImage(im1_Image);
  3410.     }
  3411.     if (im2_Image)
  3412.     {
  3413.       im2_Image->data = 0;
  3414.       XDestroyImage(im2_Image);
  3415.     }
  3416.   }
  3417. #endif
  3418. #if XWIN
  3419.   if (theImage) 
  3420.   {
  3421.     theImage->data = 0;
  3422.     XDestroyImage(theImage);
  3423.   }
  3424.   if (theDisp) XtCloseDisplay(theDisp);
  3425. #endif
  3426.   while(xa_chdr_start)
  3427.   {
  3428.     XA_CHDR *tmp;
  3429.     tmp = xa_chdr_start;
  3430.     xa_chdr_start = xa_chdr_start->next;
  3431.     if (tmp->cmap) { FREE(tmp->cmap,0x01); tmp->cmap=0; }
  3432.     if (tmp->map) { FREE(tmp->map,0x01); tmp->map=0; }
  3433.     FREE(tmp,0x01);
  3434.   }
  3435.   exit(0);
  3436. }
  3437.  
  3438.  
  3439. /*
  3440.  * just prints a message before calling TheEnd()
  3441.  */
  3442. void TheEnd1(err_mess)
  3443. char *err_mess;
  3444. {
  3445.  fprintf(stderr,"%s\n",err_mess);
  3446.  TheEnd();
  3447. }
  3448.  
  3449.  
  3450.